diff --git a/core/src/main/java/hudson/search/Search.java b/core/src/main/java/hudson/search/Search.java
index 89a16b7e6d..3b2f8e8de0 100644
--- a/core/src/main/java/hudson/search/Search.java
+++ b/core/src/main/java/hudson/search/Search.java
@@ -11,12 +11,12 @@ import org.kohsuke.stapler.export.Flavor;
import javax.servlet.ServletException;
import java.io.IOException;
+import java.util.AbstractList;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
-import java.util.StringTokenizer;
/**
* Web-bound object that serves QuickSilver-like search requests.
@@ -142,38 +142,73 @@ public class Search {
return items;
}
+ static final class TokenList {
+ private final String[] tokens;
+
+ public TokenList(String tokenList) {
+ tokens = tokenList.split("(?<=\\s)(?=\\S)");
+ }
+
+ public int length() { return tokens.length; }
+
+ /**
+ * Returns {@link List} such that its get(end)
+ * returns the concatanation of [token_start,...,token_end]
+ * (both end inclusive.)
+ */
+ public List subSequence(final int start) {
+ return new AbstractList() {
+ public String get(int index) {
+ StringBuilder buf = new StringBuilder();
+ for(int i=start; i<=start+index; i++ )
+ buf.append(tokens[i]);
+ return buf.toString().trim();
+ }
+
+ public int size() {
+ return tokens.length-start;
+ }
+ };
+ }
+ }
+
private static List find(Mode m, SearchIndex index, String tokenList) {
- List front = new ArrayList();
- List back = new ArrayList();
+ TokenList tokens = new TokenList(tokenList);
+ if(tokens.length()==0) return Collections.emptyList(); // no tokens given
+
+ List[] paths = new List[tokens.length()+1]; // we won't use [0].
+ for(int i=1;i<=tokens.length();i++)
+ paths[i] = new ArrayList();
+
List items = new ArrayList(); // items found in 1 step
- StringTokenizer tokens = new StringTokenizer(tokenList);
- if(!tokens.hasMoreTokens()) return front; // no tokens given
// first token
- m.find(index,tokens.nextToken(),items);
- for (SearchItem i : items)
- front.add(new SuggestedItem(i));
+ int w=1; // width of token
+ for (String token : tokens.subSequence(0)) {
+ items.clear();
+ m.find(index,token,items);
+ for (SearchItem si : items)
+ paths[w].add(new SuggestedItem(si));
+ w++;
+ }
// successive tokens
- while(tokens.hasMoreTokens()) {
- String token = tokens.nextToken();
-
- back.clear();
- for (SuggestedItem r : front) {
- items.clear();
- m.find(r.item.getSearchIndex(),token,items);
- for (SearchItem i : items)
- back.add(new SuggestedItem(r,i));
- }
-
- {// swap front and back
- List t = front;
- front = back;
- back = t;
+ for (int j=1; j