Index: lucene/src/test/org/apache/lucene/TestSearchForDuplicates.java
===================================================================
--- lucene/src/test/org/apache/lucene/TestSearchForDuplicates.java	(revision 1138276)
+++ lucene/src/test/org/apache/lucene/TestSearchForDuplicates.java	Mon Jul 04 16:06:23 NZST 2011
@@ -27,7 +27,6 @@
 import org.apache.lucene.analysis.*;
 import org.apache.lucene.index.*;
 import org.apache.lucene.search.*;
-import org.apache.lucene.queryParser.*;
 import org.apache.lucene.util.LuceneTestCase;
 import junit.framework.TestSuite;
 import junit.textui.TestRunner;
@@ -102,9 +101,7 @@
       // try a search without OR
       IndexSearcher searcher = new IndexSearcher(directory, true);
 
-      QueryParser parser = new QueryParser(TEST_VERSION_CURRENT, PRIORITY_FIELD, analyzer);
-
-      Query query = parser.parse(HIGH_PRIORITY);
+      Query query = new TermQuery(new Term(PRIORITY_FIELD, HIGH_PRIORITY));
       out.println("Query: " + query.toString(PRIORITY_FIELD));
       if (VERBOSE) {
         System.out.println("TEST: search query=" + query);
@@ -124,9 +121,7 @@
       searcher = new IndexSearcher(directory, true);
       hits = null;
 
-      parser = new QueryParser(TEST_VERSION_CURRENT, PRIORITY_FIELD, analyzer);
-
-      query = parser.parse(HIGH_PRIORITY + " OR " + MED_PRIORITY);
+      query = new MockQueryParser(PRIORITY_FIELD, new MockAnalyzer(random)).parse(HIGH_PRIORITY + " " + MED_PRIORITY);
       out.println("Query: " + query.toString(PRIORITY_FIELD));
 
       hits = searcher.search(query, null, MAX_DOCS, sort).scoreDocs;
Index: lucene/src/test/org/apache/lucene/search/TestPositionIncrement.java
===================================================================
--- lucene/src/test/org/apache/lucene/search/TestPositionIncrement.java	(revision 1133805)
+++ lucene/src/test/org/apache/lucene/search/TestPositionIncrement.java	Mon Jul 04 20:27:21 NZST 2011
@@ -37,7 +37,6 @@
 import org.apache.lucene.index.RandomIndexWriter;
 import org.apache.lucene.index.SlowMultiReaderWrapper;
 import org.apache.lucene.index.Term;
-import org.apache.lucene.queryParser.QueryParser;
 import org.apache.lucene.store.Directory;
 import org.apache.lucene.search.payloads.PayloadSpanUtil;
 import org.apache.lucene.search.spans.MultiSpansWrapper;
@@ -193,39 +192,7 @@
     q.add(new Term("field", "5"));
     hits = searcher.search(q, null, 1000).scoreDocs;
     assertEquals(0, hits.length);
-
+    
-    // should not find "1 2" because there is a gap of 1 in the index
-    QueryParser qp = new QueryParser(TEST_VERSION_CURRENT, "field",
-        new MockAnalyzer(random, MockTokenizer.WHITESPACE, false, stopStopList, false));
-    q = (PhraseQuery) qp.parse("\"1 2\"");
-    hits = searcher.search(q, null, 1000).scoreDocs;
-    assertEquals(0, hits.length);
-
-    // omitted stop word cannot help because stop filter swallows the increments. 
-    q = (PhraseQuery) qp.parse("\"1 stop 2\"");
-    hits = searcher.search(q, null, 1000).scoreDocs;
-    assertEquals(0, hits.length);
-
-    // query parser alone won't help, because stop filter swallows the increments. 
-    qp.setEnablePositionIncrements(true);
-    q = (PhraseQuery) qp.parse("\"1 stop 2\"");
-    hits = searcher.search(q, null, 1000).scoreDocs;
-    assertEquals(0, hits.length);
-
-    // stop filter alone won't help, because query parser swallows the increments. 
-    qp.setEnablePositionIncrements(false);
-    q = (PhraseQuery) qp.parse("\"1 stop 2\"");
-    hits = searcher.search(q, null, 1000).scoreDocs;
-    assertEquals(0, hits.length);
-      
-    // when both qp qnd stopFilter propagate increments, we should find the doc.
-    qp = new QueryParser(TEST_VERSION_CURRENT, "field",
-                         new MockAnalyzer(random, MockTokenizer.WHITESPACE, false, stopStopList, true));
-    qp.setEnablePositionIncrements(true);
-    q = (PhraseQuery) qp.parse("\"1 stop 2\"");
-    hits = searcher.search(q, null, 1000).scoreDocs;
-    assertEquals(1, hits.length);
-    
     searcher.close();
     reader.close();
     store.close();
@@ -323,4 +290,4 @@
     is.getIndexReader().close();
     dir.close();
   }
-}
\ No newline at end of file
+}
Index: lucene/src/test/org/apache/lucene/queryParser/TestMultiPhraseQueryParsing.java
===================================================================
--- lucene/src/test/org/apache/lucene/queryParser/TestMultiPhraseQueryParsing.java	Mon Jul 04 16:06:23 NZST 2011
+++ lucene/src/test/org/apache/lucene/queryParser/TestMultiPhraseQueryParsing.java	Mon Jul 04 16:06:23 NZST 2011
@@ -0,0 +1,105 @@
+package org.apache.lucene.queryParser;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.apache.lucene.analysis.Analyzer;
+import org.apache.lucene.analysis.TokenStream;
+import org.apache.lucene.analysis.Tokenizer;
+import org.apache.lucene.analysis.tokenattributes.CharTermAttribute;
+import org.apache.lucene.analysis.tokenattributes.PositionIncrementAttribute;
+import org.apache.lucene.index.Term;
+import org.apache.lucene.search.MultiPhraseQuery;
+import org.apache.lucene.search.Query;
+import org.apache.lucene.util.LuceneTestCase;
+
+import java.io.IOException;
+import java.io.Reader;
+
+public class TestMultiPhraseQueryParsing extends LuceneTestCase {
+
+  private static class TokenAndPos {
+      public final String token;
+      public final int pos;
+      public TokenAndPos(String token, int pos) {
+        this.token = token;
+        this.pos = pos;
+      }
+    }
+
+  private static class CannedAnalyzer extends Analyzer {
+    private final TokenAndPos[] tokens;
+
+    public CannedAnalyzer(TokenAndPos[] tokens) {
+      this.tokens = tokens;
+    }
+
+    @Override
+    public TokenStream tokenStream(String fieldName, Reader reader) {
+      return new CannedTokenizer(tokens);
+    }
+  }
+
+  private static class CannedTokenizer extends Tokenizer {
+    private final TokenAndPos[] tokens;
+    private int upto = 0;
+    private int lastPos = 0;
+    private final CharTermAttribute termAtt = addAttribute(CharTermAttribute.class);
+    private final PositionIncrementAttribute posIncrAtt = addAttribute(PositionIncrementAttribute.class);
+
+    public CannedTokenizer(TokenAndPos[] tokens) {
+      this.tokens = tokens;
+    }
+
+    @Override
+    public final boolean incrementToken() throws IOException {
+      clearAttributes();
+      if (upto < tokens.length) {
+        final TokenAndPos token = tokens[upto++];
+        termAtt.setEmpty();
+        termAtt.append(token.token);
+        posIncrAtt.setPositionIncrement(token.pos - lastPos);
+        lastPos = token.pos;
+        return true;
+      } else {
+        return false;
+      }
+    }
+  }
+
+  public void testMultiPhraseQueryParsing() throws Exception {
+    TokenAndPos[] INCR_0_QUERY_TOKENS_AND = new TokenAndPos[]{
+        new TokenAndPos("a", 0),
+        new TokenAndPos("1", 0),
+        new TokenAndPos("b", 1),
+        new TokenAndPos("1", 1),
+        new TokenAndPos("c", 2)
+    };
+
+    QueryParser qp = new QueryParser(TEST_VERSION_CURRENT, "field", new CannedAnalyzer(INCR_0_QUERY_TOKENS_AND));
+    Query q = qp.parse("\"this text is acually ignored\"");
+    assertTrue("wrong query type!", q instanceof MultiPhraseQuery);
+
+    MultiPhraseQuery multiPhraseQuery = new MultiPhraseQuery();
+    multiPhraseQuery.add(new Term[]{ new Term("field", "a"), new Term("field", "1") }, -1);
+    multiPhraseQuery.add(new Term[]{ new Term("field", "b"), new Term("field", "1") }, 0);
+    multiPhraseQuery.add(new Term[]{ new Term("field", "c") }, 1);
+
+    assertEquals(multiPhraseQuery, q);
+  }
+
+}
Index: lucene/src/test/org/apache/lucene/index/values/TestDocValuesIndexing.java
===================================================================
--- lucene/src/test/org/apache/lucene/index/values/TestDocValuesIndexing.java	(revision 1141100)
+++ lucene/src/test/org/apache/lucene/index/values/TestDocValuesIndexing.java	Mon Jul 04 20:27:21 NZST 2011
@@ -42,9 +42,8 @@
 import org.apache.lucene.index.codecs.CodecProvider;
 import org.apache.lucene.index.codecs.PerDocValues;
 import org.apache.lucene.index.values.IndexDocValues.Source;
-import org.apache.lucene.queryParser.ParseException;
-import org.apache.lucene.queryParser.QueryParser;
 import org.apache.lucene.search.IndexSearcher;
+import org.apache.lucene.search.MockQueryParser;
 import org.apache.lucene.search.ScoreDoc;
 import org.apache.lucene.search.TopDocs;
 import org.apache.lucene.store.Directory;
@@ -77,8 +76,7 @@
   /*
    * Simple test case to show how to use the API
    */
-  public void testDocValuesSimple() throws CorruptIndexException, IOException,
-      ParseException {
+  public void testDocValuesSimple() throws CorruptIndexException, IOException {
     Directory dir = newDirectory();
     IndexWriter writer = new IndexWriter(dir, writerConfig(false));
     for (int i = 0; i < 5; i++) {
@@ -98,9 +96,8 @@
     assertTrue(reader.isOptimized());
 
     IndexSearcher searcher = new IndexSearcher(reader);
-    QueryParser parser = new QueryParser(TEST_VERSION_CURRENT, "docId",
-        new MockAnalyzer(random));
-    TopDocs search = searcher.search(parser.parse("0 OR 1 OR 2 OR 3 OR 4"), 10);
+    MockQueryParser parser = new MockQueryParser("docId", new MockAnalyzer(random));
+    TopDocs search = searcher.search(parser.parse("0 1 2 3 4"), 10);
     assertEquals(5, search.totalHits);
     ScoreDoc[] scoreDocs = search.scoreDocs;
     IndexDocValues docValues = MultiPerDocValues.getPerDocs(reader).docValues("docId");
Index: lucene/src/test/org/apache/lucene/search/TestMultiPhraseQuery.java
===================================================================
--- lucene/src/test/org/apache/lucene/search/TestMultiPhraseQuery.java	(revision 1139788)
+++ lucene/src/test/org/apache/lucene/search/TestMultiPhraseQuery.java	Mon Jul 04 16:06:23 NZST 2011
@@ -24,7 +24,6 @@
 import org.apache.lucene.index.IndexReader;
 import org.apache.lucene.index.MultiFields;
 import org.apache.lucene.queryParser.ParseException;
-import org.apache.lucene.queryParser.QueryParser;
 import org.apache.lucene.search.Explanation.IDFExplanation;
 import org.apache.lucene.store.Directory;
 import org.apache.lucene.util.BytesRef;
@@ -479,13 +478,17 @@
    * in each position - one of each position is sufficient (OR logic)
    */
   public void testZeroPosIncrSloppyParsedAnd() throws IOException, ParseException {
-    QueryParser qp = new QueryParser(TEST_VERSION_CURRENT, "field", new CannedAnalyzer(INCR_0_QUERY_TOKENS_AND));
-    final Query q = qp.parse("\"this text is acually ignored\"");
-    assertTrue("wrong query type!", q instanceof MultiPhraseQuery);
+//    QueryParser qp = new QueryParser(TEST_VERSION_CURRENT, "field", new CannedAnalyzer(INCR_0_QUERY_TOKENS_AND)); // nocommit - move this to its own test
+//    final Query q = qp.parse("\"this text is acually ignored\"");
+//    assertTrue("wrong query type!", q instanceof MultiPhraseQuery);
+    MultiPhraseQuery q = new MultiPhraseQuery();
+    q.add(new Term[]{ new Term("field", "a"), new Term("field", "1") }, -1);
+    q.add(new Term[]{ new Term("field", "b"), new Term("field", "1") }, 0);
+    q.add(new Term[]{ new Term("field", "c") }, 1);
     doTestZeroPosIncrSloppy(q, 0);
-    ((MultiPhraseQuery) q).setSlop(1);
+    q.setSlop(1);
     doTestZeroPosIncrSloppy(q, 0);
-    ((MultiPhraseQuery) q).setSlop(2);
+    q.setSlop(2);
     doTestZeroPosIncrSloppy(q, 1);
   }
   
Index: lucene/src/test/org/apache/lucene/search/TestBoolean2.java
===================================================================
--- lucene/src/test/org/apache/lucene/search/TestBoolean2.java	(revision 1133616)
+++ lucene/src/test/org/apache/lucene/search/TestBoolean2.java	Mon Jul 04 16:06:23 NZST 2011
@@ -18,6 +18,7 @@
  */
 
 
+import java.io.IOException;
 import java.util.Random;
 
 import org.apache.lucene.analysis.MockAnalyzer;
@@ -26,8 +27,6 @@
 import org.apache.lucene.index.RandomIndexWriter;
 import org.apache.lucene.index.Term;
 import org.apache.lucene.index.IndexReader;
-import org.apache.lucene.queryParser.ParseException;
-import org.apache.lucene.queryParser.QueryParser;
 import org.apache.lucene.store.Directory;
 import org.apache.lucene.store.MockDirectoryWrapper;
 import org.apache.lucene.store.RAMDirectory;
@@ -117,9 +116,8 @@
     "w1 w3 xx w2 yy w3"
   };
 
-  public Query makeQuery(String queryText) throws ParseException {
-    Query q = (new QueryParser(TEST_VERSION_CURRENT, field, new MockAnalyzer(random))).parse(queryText);
-    return q;
+  public Query makeQuery(String queryText) throws IOException {
+    return new MockQueryParser(field, new MockAnalyzer(random)).parse(queryText);
   }
 
   public void queriesTest(String queryText, int[] expDocNrs) throws Exception {
Index: lucene/src/test/org/apache/lucene/search/TestNot.java
===================================================================
--- lucene/src/test/org/apache/lucene/search/TestNot.java	(revision 1133805)
+++ lucene/src/test/org/apache/lucene/search/TestNot.java	Mon Jul 04 20:27:21 NZST 2011
@@ -21,7 +21,6 @@
 
 import org.apache.lucene.index.IndexReader;
 import org.apache.lucene.index.RandomIndexWriter;
-import org.apache.lucene.queryParser.QueryParser;
 import org.apache.lucene.store.Directory;
 import org.apache.lucene.analysis.MockAnalyzer;
 import org.apache.lucene.document.Document;
@@ -44,9 +43,10 @@
     IndexReader reader = writer.getReader();
 
     IndexSearcher searcher = newSearcher(reader);
-      QueryParser parser = new QueryParser(TEST_VERSION_CURRENT, "field", new MockAnalyzer(random));
-    Query query = parser.parse("a NOT b");
-    //System.out.println(query);
+
+    MockQueryParser queryParser = new MockQueryParser("field", new MockAnalyzer(random));
+    Query query = queryParser.parse("a -b");
+
     ScoreDoc[] hits = searcher.search(query, null, 1000).scoreDocs;
     assertEquals(0, hits.length);
     writer.close();
Index: lucene/src/test-framework/org/apache/lucene/search/QueryBuilderHelper.java
===================================================================
--- lucene/src/test-framework/org/apache/lucene/search/QueryBuilderHelper.java	Mon Jul 04 16:06:23 NZST 2011
+++ lucene/src/test-framework/org/apache/lucene/search/QueryBuilderHelper.java	Mon Jul 04 16:06:23 NZST 2011
@@ -0,0 +1,29 @@
+package org.apache.lucene.search;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.apache.lucene.index.Term;
+
+public class QueryBuilderHelper {
+
+  public static TermQuery newTermQuery(String field, String value, float boost) {
+    TermQuery termQuery = new TermQuery(new Term(field, value));
+    termQuery.setBoost(boost);
+    return termQuery;
+  }
+}
Index: lucene/src/test/org/apache/lucene/search/TestExplanations.java
===================================================================
--- lucene/src/test/org/apache/lucene/search/TestExplanations.java	(revision 1140848)
+++ lucene/src/test/org/apache/lucene/search/TestExplanations.java	Mon Jul 04 16:06:23 NZST 2011
@@ -17,8 +17,6 @@
  * limitations under the License.
  */
 
-import org.apache.lucene.queryParser.QueryParser;
-import org.apache.lucene.queryParser.ParseException;
 import org.apache.lucene.analysis.MockAnalyzer;
 import org.apache.lucene.document.Document;
 import org.apache.lucene.document.Field;
@@ -58,8 +56,8 @@
   public static final String FIELD = "field";
   // same contents, but no field boost
   public static final String ALTFIELD = "alt";
-  public static final QueryParser qp =
-    new QueryParser(TEST_VERSION_CURRENT, FIELD, new MockAnalyzer(random));
+  public static final MockQueryParser qp =
+    new MockQueryParser(FIELD, new MockAnalyzer(random));
   
   @AfterClass
   public static void afterClassTestExplanations() throws Exception {
@@ -96,7 +94,7 @@
     "w1 w3 xx w2 yy w3 zz"
   };
 
-  public Query makeQuery(String queryText) throws ParseException {
+  public Query makeQuery(String queryText) throws Exception {
     return qp.parse(queryText);
   }
 
Index: lucene/src/test-framework/org/apache/lucene/search/PhraseQueryBuilder.java
===================================================================
--- lucene/src/test-framework/org/apache/lucene/search/PhraseQueryBuilder.java	Mon Jul 04 16:39:34 NZST 2011
+++ lucene/src/test-framework/org/apache/lucene/search/PhraseQueryBuilder.java	Mon Jul 04 16:39:34 NZST 2011
@@ -0,0 +1,73 @@
+package org.apache.lucene.search;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+import org.apache.lucene.index.Term;
+
+public class PhraseQueryBuilder {
+
+  private PhraseQuery phraseQuery = new PhraseQuery();
+  private String defaultField;
+
+  public PhraseQueryBuilder() {
+  }
+
+  public PhraseQueryBuilder(String defaultField) {
+    this.defaultField = defaultField;
+  }
+
+  public PhraseQueryBuilder(String defaultField, int slop) {
+    this.defaultField = defaultField;
+    this.phraseQuery.setSlop(slop);
+  }
+
+  public PhraseQueryBuilder addTerm(String field, String value) {
+    phraseQuery.add(new Term(field, value));
+    return this;
+  }
+
+  public PhraseQueryBuilder addTerm(String value) {
+    assert defaultField != null;
+    return this.addTerm(defaultField, value);
+  }
+
+  public PhraseQueryBuilder addTerm(String field, String value, int position) {
+    phraseQuery.add(new Term(field, value), position);
+    return this;
+  }
+
+  public PhraseQueryBuilder addTerm(String value, int position) {
+    assert defaultField != null;
+    return this.addTerm(defaultField, value, position);
+  }
+
+  public PhraseQueryBuilder reset() {
+    phraseQuery = new PhraseQuery();
+    return this;
+  }
+
+  public PhraseQueryBuilder setSlop(int slop) {
+    this.phraseQuery.setSlop(slop);
+    return this;
+  }
+
+  public PhraseQuery get() {
+    return phraseQuery;
+  }
+}
Index: lucene/src/test-framework/org/apache/lucene/search/MockQueryParser.java
===================================================================
--- lucene/src/test-framework/org/apache/lucene/search/MockQueryParser.java	Mon Jul 04 16:06:23 NZST 2011
+++ lucene/src/test-framework/org/apache/lucene/search/MockQueryParser.java	Mon Jul 04 16:06:23 NZST 2011
@@ -0,0 +1,82 @@
+package org.apache.lucene.search;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.apache.lucene.analysis.Analyzer;
+import org.apache.lucene.analysis.TokenStream;
+import org.apache.lucene.analysis.tokenattributes.TermToBytesRefAttribute;
+import org.apache.lucene.index.Term;
+import org.apache.lucene.util.BytesRef;
+
+import java.io.IOException;
+import java.io.StringReader;
+
+public class MockQueryParser {
+
+  private final Analyzer analyzer;
+  private final String field;
+
+  public MockQueryParser(String field, Analyzer analyzer) {
+    this.analyzer = analyzer;
+    this.field = field;
+  }
+
+  public Query parse(String queryString) throws IOException {
+    String[] terms = queryString.split("\\s+");
+
+    BooleanQuery query = new BooleanQuery();
+
+    for (String queryTerm : terms) {
+
+      BooleanClause.Occur occur = BooleanClause.Occur.SHOULD;
+      if (queryTerm.charAt(0) == '+') {
+        occur = BooleanClause.Occur.MUST;
+        queryTerm = queryTerm.substring(1);
+      } else if (queryTerm.charAt(0) == '-') {
+        occur = BooleanClause.Occur.MUST_NOT;
+        queryTerm = queryTerm.substring(1);
+      }
+
+      int fieldIndex = queryTerm.indexOf(':');
+      String field = this.field;
+      if (fieldIndex != -1) {
+        field = queryTerm.substring(0, fieldIndex);
+        queryTerm = queryTerm.substring(fieldIndex + 1);
+      }
+        
+      if (queryTerm.contains("*") || queryTerm.contains("?")) { // Wildcard query
+        query.add(new WildcardQuery(new Term(field, queryTerm)), occur);
+      } else {
+        TokenStream tokenStream = analyzer.reusableTokenStream(field, new StringReader(queryTerm));
+        tokenStream.reset();
+
+        TermToBytesRefAttribute bytesRefAttribute = tokenStream.getAttribute(TermToBytesRefAttribute.class);
+        BytesRef bytesRef = bytesRefAttribute.getBytesRef();
+        while (tokenStream.incrementToken()) {
+          bytesRefAttribute.fillBytesRef();
+          query.add(new TermQuery(new Term(field, new BytesRef(bytesRef))), occur);
+        }
+
+        tokenStream.end();
+        tokenStream.close();
+      }
+    }
+
+    return query;
+  }
+}
Index: lucene/src/test/org/apache/lucene/search/MockQueryParserTest.java
===================================================================
--- lucene/src/test/org/apache/lucene/search/MockQueryParserTest.java	Mon Jul 04 20:27:21 NZST 2011
+++ lucene/src/test/org/apache/lucene/search/MockQueryParserTest.java	Mon Jul 04 20:27:21 NZST 2011
@@ -0,0 +1,69 @@
+package org.apache.lucene.search;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.apache.lucene.analysis.MockAnalyzer;
+import org.apache.lucene.index.Term;
+import org.apache.lucene.util.LuceneTestCase;
+
+import java.io.IOException;
+
+public class MockQueryParserTest extends LuceneTestCase {
+
+  public void testParse_simpleTwoTerms() throws IOException {
+    MockQueryParser queryParser = new MockQueryParser("field", new MockAnalyzer(random));
+    Query query = queryParser.parse("a b");
+
+    assertEquals(BooleanQuery.class, query.getClass());
+
+    BooleanQuery booleanQuery = (BooleanQuery) query;
+
+    assertEquals(2, booleanQuery.clauses().size());
+    assertEquals(new TermQuery(new Term("field", "a")), booleanQuery.clauses().get(0).getQuery());
+    assertEquals(new TermQuery(new Term("field", "b")), booleanQuery.clauses().get(1).getQuery());
+  }
+
+  public void testParse_termsWithBooleanOperators() throws IOException {
+    MockQueryParser queryParser = new MockQueryParser("field", new MockAnalyzer(random));
+    Query query = queryParser.parse("+a -b");
+
+    assertEquals(BooleanQuery.class, query.getClass());
+
+    BooleanQuery booleanQuery = (BooleanQuery) query;
+
+    assertEquals(2, booleanQuery.clauses().size());
+    assertEquals(new TermQuery(new Term("field", "a")), booleanQuery.clauses().get(0).getQuery());
+    assertEquals(BooleanClause.Occur.MUST, booleanQuery.clauses().get(0).getOccur());
+    assertEquals(new TermQuery(new Term("field", "b")), booleanQuery.clauses().get(1).getQuery());
+    assertEquals(BooleanClause.Occur.MUST_NOT, booleanQuery.clauses().get(1).getOccur());
+  }
+
+  public void testParse_wildCardQuery() throws IOException {
+    MockQueryParser queryParser = new MockQueryParser("field", new MockAnalyzer(random));
+    BooleanQuery booleanQuery = (BooleanQuery) queryParser.parse("a*");
+
+    assertEquals(new WildcardQuery(new Term("field", "a*")), booleanQuery.clauses().get(0).getQuery());
+  }
+
+  public void testParse_queryWithField() throws IOException {
+    MockQueryParser queryParser = new MockQueryParser("field", new MockAnalyzer(random));
+    BooleanQuery booleanQuery = (BooleanQuery) queryParser.parse("alt:a");
+
+    assertEquals(new TermQuery(new Term("alt", "a")), booleanQuery.clauses().get(0).getQuery());
+  }
+}
Index: lucene/src/test/org/apache/lucene/search/TestWildcard.java
===================================================================
--- lucene/src/test/org/apache/lucene/search/TestWildcard.java	(revision 1091132)
+++ lucene/src/test/org/apache/lucene/search/TestWildcard.java	Mon Jul 04 16:06:23 NZST 2011
@@ -28,7 +28,6 @@
 import org.apache.lucene.index.RandomIndexWriter;
 import org.apache.lucene.index.Term;
 import org.apache.lucene.index.Terms;
-import org.apache.lucene.queryParser.QueryParser;
 
 import java.io.IOException;
 
@@ -268,28 +267,30 @@
    */
   public void testParsingAndSearching() throws Exception {
     String field = "content";
-    QueryParser qp = new QueryParser(TEST_VERSION_CURRENT, field, new MockAnalyzer(random));
-    qp.setAllowLeadingWildcard(true);
     String docs[] = {
         "\\ abcdefg1",
         "\\79 hijklmn1",
         "\\\\ opqrstu1",
     };
+
+    MockQueryParser queryParser = new MockQueryParser(field, new MockAnalyzer(random));
+    
     // queries that should find all docs
     String matchAll[] = {
         "*", "*1", "**1", "*?", "*?1", "?*1", "**", "***", "\\\\*"
     };
+
     // queries that should find no docs
     String matchNone[] = {
         "a*h", "a?h", "*a*h", "?a", "a?",
     };
-    // queries that should be parsed to prefix queries
-    String matchOneDocPrefix[][] = {
-        {"a*", "ab*", "abc*", }, // these should find only doc 0 
-        {"h*", "hi*", "hij*", "\\\\7*"}, // these should find only doc 1
-        {"o*", "op*", "opq*", "\\\\\\\\*"}, // these should find only doc 2
+
+    PrefixQuery matchOneDocPrefix[][] = {
+        { newPrefixQuery(field, "a"), newPrefixQuery(field, "ab"), newPrefixQuery(field, "abc") }, // these should find only doc 0
+        { newPrefixQuery(field, "h"), newPrefixQuery(field, "hi"), newPrefixQuery(field, "hij"), newPrefixQuery(field, "\\7")}, // these should find only doc 1
+        { newPrefixQuery(field, "o"), newPrefixQuery(field, "op"), newPrefixQuery(field, "opq"), newPrefixQuery(field, "\\\\")}, // these should find only doc 2
     };
-    // queries that should be parsed to wildcard queries
+
     String matchOneDocWild[][] = {
         {"*a*", "*ab*", "*abc**", "ab*e*", "*g?", "*f?1", "abc**"}, // these should find only doc 0
         {"*h*", "*hi*", "*hij**", "hi*k*", "*n?", "*m?1", "hij**"}, // these should find only doc 1
@@ -313,7 +314,7 @@
     // test queries that must find all
     for (int i = 0; i < matchAll.length; i++) {
       String qtxt = matchAll[i];
-      Query q = qp.parse(qtxt);
+      Query q = queryParser.parse(qtxt);
       if (VERBOSE) System.out.println("matchAll: qtxt="+qtxt+" q="+q+" "+q.getClass().getName());
       ScoreDoc[] hits = searcher.search(q, null, 1000).scoreDocs;
       assertEquals(docs.length,hits.length);
@@ -322,32 +323,29 @@
     // test queries that must find none
     for (int i = 0; i < matchNone.length; i++) {
       String qtxt = matchNone[i];
-      Query q = qp.parse(qtxt);
+      Query q = queryParser.parse(qtxt);
       if (VERBOSE) System.out.println("matchNone: qtxt="+qtxt+" q="+q+" "+q.getClass().getName());
       ScoreDoc[] hits = searcher.search(q, null, 1000).scoreDocs;
       assertEquals(0,hits.length);
     }
 
-    // test queries that must be prefix queries and must find only one doc
+    // thest the prefi queries find only one doc
     for (int i = 0; i < matchOneDocPrefix.length; i++) {
       for (int j = 0; j < matchOneDocPrefix[i].length; j++) {
-        String qtxt = matchOneDocPrefix[i][j];
-        Query q = qp.parse(qtxt);
-        if (VERBOSE) System.out.println("match 1 prefix: doc="+docs[i]+" qtxt="+qtxt+" q="+q+" "+q.getClass().getName());
-        assertEquals(PrefixQuery.class, q.getClass());
+        Query q = matchOneDocPrefix[i][j];
+        if (VERBOSE) System.out.println("match 1 prefix: doc="+docs[i]+" q="+q+" "+q.getClass().getName());
         ScoreDoc[] hits = searcher.search(q, null, 1000).scoreDocs;
         assertEquals(1,hits.length);
         assertEquals(i,hits[0].doc);
       }
     }
 
-    // test queries that must be wildcard queries and must find only one doc
-    for (int i = 0; i < matchOneDocPrefix.length; i++) {
+    // test the wildcard queries find only one doc
+    for (int i = 0; i < matchOneDocWild.length; i++) {
       for (int j = 0; j < matchOneDocWild[i].length; j++) {
         String qtxt = matchOneDocWild[i][j];
-        Query q = qp.parse(qtxt);
+        Query q = queryParser.parse(qtxt);
         if (VERBOSE) System.out.println("match 1 wild: doc="+docs[i]+" qtxt="+qtxt+" q="+q+" "+q.getClass().getName());
-        assertEquals(WildcardQuery.class, q.getClass());
         ScoreDoc[] hits = searcher.search(q, null, 1000).scoreDocs;
         assertEquals(1,hits.length);
         assertEquals(i,hits[0].doc);
@@ -357,4 +355,8 @@
     searcher.close();
     dir.close();
   }
+
+  private PrefixQuery newPrefixQuery(String field, String term) {
+    return new PrefixQuery(new Term(field, term));
-}
+  }
+}
Index: lucene/src/test/org/apache/lucene/search/TestDateSort.java
===================================================================
--- lucene/src/test/org/apache/lucene/search/TestDateSort.java	(revision 1138276)
+++ lucene/src/test/org/apache/lucene/search/TestDateSort.java	Mon Jul 04 20:27:21 NZST 2011
@@ -19,6 +19,7 @@
 
 import java.util.Arrays;
 
+import org.apache.lucene.index.Term;
 import org.apache.lucene.util.LuceneTestCase;
 
 import org.apache.lucene.analysis.MockAnalyzer;
@@ -27,7 +28,6 @@
 import org.apache.lucene.document.Field;
 import org.apache.lucene.index.IndexReader;
 import org.apache.lucene.index.RandomIndexWriter;
-import org.apache.lucene.queryParser.QueryParser;
 import org.apache.lucene.search.Query;
 import org.apache.lucene.search.Sort;
 import org.apache.lucene.search.SortField;
@@ -80,10 +80,8 @@
     IndexSearcher searcher = newSearcher(reader);
 
     Sort sort = new Sort(new SortField(DATE_TIME_FIELD, SortField.Type.STRING, true));
+    Query query = new TermQuery(new Term(TEXT_FIELD, "document"));
 
-    QueryParser queryParser = new QueryParser(TEST_VERSION_CURRENT, TEXT_FIELD, new MockAnalyzer(random));
-    Query query = queryParser.parse("Document");
-
     // Execute the search and process the search results.
     String[] actualOrder = new String[5];
     ScoreDoc[] hits = searcher.search(query, null, 1000, sort).scoreDocs;
Index: lucene/src/test/org/apache/lucene/search/TestBooleanQuery.java
===================================================================
--- lucene/src/test/org/apache/lucene/search/TestBooleanQuery.java	(revision 1091132)
+++ lucene/src/test/org/apache/lucene/search/TestBooleanQuery.java	Mon Jul 04 16:06:23 NZST 2011
@@ -28,7 +28,6 @@
 import org.apache.lucene.index.MultiReader;
 import org.apache.lucene.index.RandomIndexWriter;
 import org.apache.lucene.index.Term;
-import org.apache.lucene.queryParser.QueryParser;
 import org.apache.lucene.store.Directory;
 import org.apache.lucene.util.LuceneTestCase;
 import org.apache.lucene.util.NamedThreadFactory;
@@ -142,19 +141,22 @@
     iw2.addDocument(doc2);
     IndexReader reader2 = iw2.getReader();
     iw2.close();
-    
+
-    QueryParser qp = new QueryParser(TEST_VERSION_CURRENT, "field", new MockAnalyzer(random));
-    qp.setMultiTermRewriteMethod(MultiTermQuery.SCORING_BOOLEAN_QUERY_REWRITE);
+    BooleanQuery query = new BooleanQuery(); // Query: +foo -ba*
+    query.add(new TermQuery(new Term("field", "foo")), BooleanClause.Occur.MUST);
+    WildcardQuery wildcardQuery = new WildcardQuery(new Term("field", "ba*"));
+    wildcardQuery.setRewriteMethod(MultiTermQuery.SCORING_BOOLEAN_QUERY_REWRITE);
+    query.add(wildcardQuery, BooleanClause.Occur.MUST_NOT);
     
     MultiReader multireader = new MultiReader(reader1, reader2);
     IndexSearcher searcher = new IndexSearcher(multireader);
-    assertEquals(0, searcher.search(qp.parse("+foo -ba*"), 10).totalHits);
+    assertEquals(0, searcher.search(query, 10).totalHits);
     
     final ExecutorService es = Executors.newCachedThreadPool(new NamedThreadFactory("NRT search threads"));
     searcher = new IndexSearcher(multireader, es);
     if (VERBOSE)
-      System.out.println("rewritten form: " + searcher.rewrite(qp.parse("+foo -ba*")));
-    assertEquals(0, searcher.search(qp.parse("+foo -ba*"), 10).totalHits);
+      System.out.println("rewritten form: " + searcher.rewrite(query));
+    assertEquals(0, searcher.search(query, 10).totalHits);
     es.shutdown();
     es.awaitTermination(1, TimeUnit.SECONDS);
 
Index: lucene/src/test/org/apache/lucene/search/spans/TestNearSpansOrdered.java
===================================================================
--- lucene/src/test/org/apache/lucene/search/spans/TestNearSpansOrdered.java	(revision 1136568)
+++ lucene/src/test/org/apache/lucene/search/spans/TestNearSpansOrdered.java	Mon Jul 04 16:06:23 NZST 2011
@@ -25,7 +25,6 @@
 import org.apache.lucene.index.IndexReader.ReaderContext;
 import org.apache.lucene.index.RandomIndexWriter;
 import org.apache.lucene.index.Term;
-import org.apache.lucene.queryParser.QueryParser;
 import org.apache.lucene.search.CheckHits;
 import org.apache.lucene.search.Explanation;
 import org.apache.lucene.search.IndexSearcher;
@@ -42,8 +41,6 @@
   protected IndexReader reader;
 
   public static final String FIELD = "field";
-  public static final QueryParser qp =
-    new QueryParser(TEST_VERSION_CURRENT, FIELD, new MockAnalyzer(random));
 
   @Override
   public void tearDown() throws Exception {
Index: lucene/src/test/org/apache/lucene/TestSearch.java
===================================================================
--- lucene/src/test/org/apache/lucene/TestSearch.java	(revision 1138276)
+++ lucene/src/test/org/apache/lucene/TestSearch.java	Mon Jul 04 16:39:34 NZST 2011
@@ -30,7 +30,6 @@
 import org.apache.lucene.analysis.*;
 import org.apache.lucene.index.*;
 import org.apache.lucene.search.*;
-import org.apache.lucene.queryParser.*;
 
 /** JUnit adaptation of an older test case SearchTest. */
 public class TestSearch extends LuceneTestCase {
@@ -100,13 +99,16 @@
 
       IndexSearcher searcher = new IndexSearcher(directory, true);
 
-      String[] queries = {
-        "a b",
-        "\"a b\"",
-        "\"a b c\"",
-        "a c",
-        "\"a c\"",
-        "\"a c e\"",
+      MockQueryParser queryParser = new MockQueryParser("contents", analyzer);
+      PhraseQueryBuilder queryBuilder = new PhraseQueryBuilder("contets");
+
+      Query[] queries = new Query[] {
+          queryParser.parse("a b"),
+          queryBuilder.addTerm("a").addTerm("b").get(),
+          queryBuilder.reset().addTerm("a").addTerm("b").addTerm("c").get(),
+          queryParser.parse("a c"),
+          queryBuilder.reset().addTerm("a").addTerm("c").get(),
+          queryBuilder.reset().addTerm("a").addTerm("c").addTerm("e").get()
       };
       ScoreDoc[] hits = null;
 
@@ -114,10 +116,8 @@
           SortField.FIELD_SCORE,
           new SortField("id", SortField.Type.INT)});
 
-      QueryParser parser = new QueryParser(TEST_VERSION_CURRENT, "contents", analyzer);
-      parser.setPhraseSlop(4);
       for (int j = 0; j < queries.length; j++) {
-        Query query = parser.parse(queries[j]);
+        Query query = queries[j];
         out.println("Query: " + query.toString("contents"));
         if (VERBOSE) {
           System.out.println("TEST: query=" + query);
Index: lucene/src/test/org/apache/lucene/search/TestPhraseQuery.java
===================================================================
--- lucene/src/test/org/apache/lucene/search/TestPhraseQuery.java	(revision 1137477)
+++ lucene/src/test/org/apache/lucene/search/TestPhraseQuery.java	Mon Jul 04 20:27:21 NZST 2011
@@ -23,7 +23,6 @@
 import org.apache.lucene.document.*;
 import org.apache.lucene.index.*;
 import org.apache.lucene.index.IndexWriterConfig.OpenMode;
-import org.apache.lucene.queryParser.QueryParser;
 import org.apache.lucene.store.*;
 import org.apache.lucene.util.Version;
 import org.apache.lucene.util._TestUtil;
@@ -382,10 +381,10 @@
   }
   
   public void testToString() throws Exception {
-    Analyzer analyzer = new MockAnalyzer(random, MockTokenizer.SIMPLE, true, MockTokenFilter.ENGLISH_STOPSET, true);
-    QueryParser qp = new QueryParser(TEST_VERSION_CURRENT, "field", analyzer);
-    qp.setEnablePositionIncrements(true);
-    PhraseQuery q = (PhraseQuery)qp.parse("\"this hi this is a test is\"");
+    PhraseQuery q = new PhraseQuery(); // Query "this hi this is a test is"
+    q.add(new Term("field", "hi"), 1);
+    q.add(new Term("field", "test"), 5);
+    
     assertEquals("field:\"? hi ? ? ? test\"", q.toString());
     q.add(new Term("field", "hello"), 1);
     assertEquals("field:\"? hi|hello ? ? ? test\"", q.toString());
Index: lucene/src/test/org/apache/lucene/queryParser/TestQueryParser.java
===================================================================
--- lucene/src/test/org/apache/lucene/queryParser/TestQueryParser.java	(revision 1091132)
+++ lucene/src/test/org/apache/lucene/queryParser/TestQueryParser.java	Mon Jul 04 16:39:34 NZST 2011
@@ -19,7 +19,6 @@
 
 import java.io.IOException;
 import java.io.Reader;
-import java.text.Collator;
 import java.text.DateFormat;
 import java.util.Calendar;
 import java.util.Date;
@@ -42,24 +41,10 @@
 import org.apache.lucene.index.IndexWriter;
 import org.apache.lucene.index.Term;
 import org.apache.lucene.index.IndexReader;
-import org.apache.lucene.search.BooleanQuery;
-import org.apache.lucene.search.BooleanClause;
-import org.apache.lucene.search.MultiTermQuery;
-import org.apache.lucene.search.FuzzyQuery;
-import org.apache.lucene.search.IndexSearcher;
-import org.apache.lucene.search.MatchAllDocsQuery;
-import org.apache.lucene.search.PhraseQuery;
-import org.apache.lucene.search.PrefixQuery;
-import org.apache.lucene.search.Query;
-import org.apache.lucene.search.RegexpQuery;
-import org.apache.lucene.search.TermRangeQuery;
-import org.apache.lucene.search.ScoreDoc;
-import org.apache.lucene.search.TermQuery;
-import org.apache.lucene.search.WildcardQuery;
+import org.apache.lucene.search.*;
 import org.apache.lucene.search.BooleanClause.Occur;
 import org.apache.lucene.store.Directory;
 import org.apache.lucene.util.LuceneTestCase;
-import org.apache.lucene.util.Version;
 import org.apache.lucene.util.automaton.BasicAutomata;
 import org.apache.lucene.util.automaton.CharacterRunAutomaton;
 import org.apache.lucene.util.automaton.RegExp;
@@ -1253,4 +1238,93 @@
     Query actual = qp.parse("[abc TO def]");
     assertEquals(expected, actual);
   }
+
+  public void testDistanceAsEditsParsing() throws Exception {
+    QueryParser qp = new QueryParser(TEST_VERSION_CURRENT, "field", new MockAnalyzer(random));
+    FuzzyQuery q = (FuzzyQuery) qp.parse("foobar~2");
+    assertEquals(2f, q.getMinSimilarity(), 0.0001f);
-}
+  }
+
+  public void testPhraseQueryToString() throws ParseException {
+    Analyzer analyzer = new MockAnalyzer(random, MockTokenizer.SIMPLE, true, MockTokenFilter.ENGLISH_STOPSET, true);
+    QueryParser qp = new QueryParser(TEST_VERSION_CURRENT, "field", analyzer);
+    qp.setEnablePositionIncrements(true);
+    PhraseQuery q = (PhraseQuery)qp.parse("\"this hi this is a test is\"");
+    assertEquals("field:\"? hi ? ? ? test\"", q.toString());
+  }
+
+  public void testParseWildcardAndPhraseQueries() throws ParseException {
+    String field = "content";
+    QueryParser qp = new QueryParser(TEST_VERSION_CURRENT, field, new MockAnalyzer(random));
+    qp.setAllowLeadingWildcard(true);
+
+    String prefixQueries[][] = {
+        {"a*", "ab*", "abc*",},
+        {"h*", "hi*", "hij*", "\\\\7*"},
+        {"o*", "op*", "opq*", "\\\\\\\\*"},
+    };
+
+    String wildcardQueries[][] = {
+        {"*a*", "*ab*", "*abc**", "ab*e*", "*g?", "*f?1", "abc**"},
+        {"*h*", "*hi*", "*hij**", "hi*k*", "*n?", "*m?1", "hij**"},
+        {"*o*", "*op*", "*opq**", "op*q*", "*u?", "*t?1", "opq**"},
+    };
+
+     // test queries that must be prefix queries
+    for (int i = 0; i < prefixQueries.length; i++) {
+      for (int j = 0; j < prefixQueries[i].length; j++) {
+        String queryString = prefixQueries[i][j];
+        Query q = qp.parse(queryString);
+        assertEquals(PrefixQuery.class, q.getClass());
+      }
+    }
+
+    // test queries that must be wildcard queries
+    for (int i = 0; i < wildcardQueries.length; i++) {
+      for (int j = 0; j < wildcardQueries[i].length; j++) {
+        String qtxt = wildcardQueries[i][j];
+        Query q = qp.parse(qtxt);
+        assertEquals(WildcardQuery.class, q.getClass());
+      }
+    }
+  }
+
+  public void testPhraseQueryPositionIncrements() throws Exception {
+    CharacterRunAutomaton stopStopList =
+    new CharacterRunAutomaton(new RegExp("[sS][tT][oO][pP]").toAutomaton());
+
+    QueryParser qp = new QueryParser(TEST_VERSION_CURRENT, "field",
+        new MockAnalyzer(random, MockTokenizer.WHITESPACE, false, stopStopList, false));
+
+    PhraseQueryBuilder queryBuilder = new PhraseQueryBuilder("field");
+    PhraseQuery phraseQuery = queryBuilder.addTerm("1").addTerm("2").get();
+
+    assertEquals(phraseQuery, qp.parse("\"1 2\""));
+    assertEquals(phraseQuery, qp.parse("\"1 stop 2\""));
+
+    qp.setEnablePositionIncrements(true);
+    assertEquals(phraseQuery, qp.parse("\"1 stop 2\""));
+
+    qp.setEnablePositionIncrements(false);
+    assertEquals(phraseQuery, qp.parse("\"1 stop 2\""));
+
+    qp = new QueryParser(TEST_VERSION_CURRENT, "field",
+                         new MockAnalyzer(random, MockTokenizer.WHITESPACE, false, stopStopList, true));
+    qp.setEnablePositionIncrements(true);
+
+    phraseQuery = queryBuilder.reset().addTerm("1").addTerm("2", 2).get();
+    assertEquals(phraseQuery, qp.parse("\"1 stop 2\""));
+  }
+
+  public void testMatchAllQueryParsing() throws Exception {
+    // test simple parsing of MatchAllDocsQuery
+    QueryParser qp = new QueryParser(TEST_VERSION_CURRENT, "key", new MockAnalyzer(random));
+    assertEquals(new MatchAllDocsQuery(), qp.parse(new MatchAllDocsQuery().toString()));
+
+    // test parsing with non-default boost
+    MatchAllDocsQuery query = new MatchAllDocsQuery();
+    query.setBoost(2.3f);
+    assertEquals(query, qp.parse(query.toString()));
+  }
+  
+}
Index: lucene/src/test/org/apache/lucene/search/TestTimeLimitingCollector.java
===================================================================
--- lucene/src/test/org/apache/lucene/search/TestTimeLimitingCollector.java	(revision 1100408)
+++ lucene/src/test/org/apache/lucene/search/TestTimeLimitingCollector.java	Mon Jul 04 16:06:23 NZST 2011
@@ -26,7 +26,6 @@
 import org.apache.lucene.index.IndexReader;
 import org.apache.lucene.index.IndexReader.AtomicReaderContext;
 import org.apache.lucene.index.RandomIndexWriter;
-import org.apache.lucene.queryParser.QueryParser;
 import org.apache.lucene.search.TimeLimitingCollector.TimeExceededException;
 import org.apache.lucene.store.Directory;
 import org.apache.lucene.util.LuceneTestCase;
@@ -89,7 +88,7 @@
     for (int i = 1; i < docText.length; i++) {
       qtxt += ' ' + docText[i]; // large query so that search will be longer
     }
-    QueryParser queryParser = new QueryParser(TEST_VERSION_CURRENT, FIELD_NAME, new MockAnalyzer(random));
+    MockQueryParser queryParser = new MockQueryParser(FIELD_NAME, new MockAnalyzer(random));
     query = queryParser.parse(qtxt);
     
     // warm the searcher
Index: lucene/src/test/org/apache/lucene/search/TestFuzzyQuery.java
===================================================================
--- lucene/src/test/org/apache/lucene/search/TestFuzzyQuery.java	(revision 1091132)
+++ lucene/src/test/org/apache/lucene/search/TestFuzzyQuery.java	Mon Jul 04 20:27:21 NZST 2011
@@ -28,7 +28,6 @@
 import org.apache.lucene.index.MultiReader;
 import org.apache.lucene.index.RandomIndexWriter;
 import org.apache.lucene.index.Term;
-import org.apache.lucene.queryParser.QueryParser;
 import org.apache.lucene.store.Directory;
 import org.apache.lucene.util.LuceneTestCase;
 
@@ -410,7 +409,7 @@
     IndexReader r = w.getReader();
     w.close();
 
-    Query q = new QueryParser(TEST_VERSION_CURRENT, "field", analyzer).parse( "giga~0.9" );
+    Query q = new FuzzyQuery(new Term("field", "giga"), 0.9f);
 
     // 3. search
     IndexSearcher searcher = newSearcher(r);
@@ -422,12 +421,6 @@
     index.close();
   }
   
-  public void testDistanceAsEditsParsing() throws Exception {
-    QueryParser qp = new QueryParser(TEST_VERSION_CURRENT, "field", new MockAnalyzer(random));
-    FuzzyQuery q = (FuzzyQuery) qp.parse("foobar~2");
-    assertEquals(2f, q.getMinSimilarity(), 0.0001f);
-  }
-  
   public void testDistanceAsEditsSearching() throws Exception {
     Directory index = newDirectory();
     RandomIndexWriter w = new RandomIndexWriter(random, index);
@@ -437,19 +430,18 @@
     IndexReader reader = w.getReader();
     IndexSearcher searcher = newSearcher(reader);
     w.close();
-    QueryParser qp = new QueryParser(TEST_VERSION_CURRENT, "field", new MockAnalyzer(random));
     
-    FuzzyQuery q = (FuzzyQuery) qp.parse("fouba~2");
+    FuzzyQuery q = new FuzzyQuery(new Term("field", "fouba"), 2);
     ScoreDoc[] hits = searcher.search(q, 10).scoreDocs;
     assertEquals(1, hits.length);
     assertEquals("foobar", searcher.doc(hits[0].doc).get("field"));
     
-    q = (FuzzyQuery) qp.parse("foubara~2");
+    q = new FuzzyQuery(new Term("field", "foubara"), 2);
     hits = searcher.search(q, 10).scoreDocs;
     assertEquals(1, hits.length);
     assertEquals("foobar", searcher.doc(hits[0].doc).get("field"));
     
-    q = (FuzzyQuery) qp.parse("t~3");
+    q = new FuzzyQuery(new Term("field", "t"), 3);
     hits = searcher.search(q, 10).scoreDocs;
     assertEquals(1, hits.length);
     assertEquals("test", searcher.doc(hits[0].doc).get("field"));
Index: lucene/src/test/org/apache/lucene/search/TestSimpleExplanations.java
===================================================================
--- lucene/src/test/org/apache/lucene/search/TestSimpleExplanations.java	(revision 1074357)
+++ lucene/src/test/org/apache/lucene/search/TestSimpleExplanations.java	Mon Jul 04 16:50:12 NZST 2011
@@ -33,7 +33,7 @@
     qtest("w1", new int[] { 0,1,2,3 });
   }
   public void testT2() throws Exception {
-    qtest("w1^1000", new int[] { 0,1,2,3 });
+    qtest(QueryBuilderHelper.newTermQuery(FIELD, "w1", 100), new int[] { 0,1,2,3 });
   }
   
   /* MatchAllDocs */
@@ -50,25 +50,25 @@
   /* some simple phrase tests */
   
   public void testP1() throws Exception {
-    qtest("\"w1 w2\"", new int[] { 0 });
+    qtest(new PhraseQueryBuilder(FIELD).addTerm("w1").addTerm("w2").get(), new int[] { 0 });
   }
   public void testP2() throws Exception {
-    qtest("\"w1 w3\"", new int[] { 1,3 });
+    qtest(new PhraseQueryBuilder(FIELD).addTerm("w1").addTerm("w3").get(), new int[] { 1,3 });
   }
   public void testP3() throws Exception {
-    qtest("\"w1 w2\"~1", new int[] { 0,1,2 });
+    qtest(new PhraseQueryBuilder(FIELD, 1).addTerm("w1").addTerm("w2").get(), new int[] { 0,1,2 });
   }
   public void testP4() throws Exception {
-    qtest("\"w2 w3\"~1", new int[] { 0,1,2,3 });
+    qtest(new PhraseQueryBuilder(FIELD, 1).addTerm("w2").addTerm("w3").get(), new int[] { 0,1,2,3 });
   }
   public void testP5() throws Exception {
-    qtest("\"w3 w2\"~1", new int[] { 1,3 });
+    qtest(new PhraseQueryBuilder(FIELD, 1).addTerm("w3").addTerm("w2").get(), new int[] { 1,3 });
   }
   public void testP6() throws Exception {
-    qtest("\"w3 w2\"~2", new int[] { 0,1,3 });
+    qtest(new PhraseQueryBuilder(FIELD, 2).addTerm("w3").addTerm("w2").get(), new int[] { 0,1,3 });
   }
   public void testP7() throws Exception {
-    qtest("\"w3 w2\"~3", new int[] { 0,1,2,3 });
+    qtest(new PhraseQueryBuilder(FIELD, 3).addTerm("w3").addTerm("w2").get(), new int[] { 0,1,2,3 });
   }
 
   /* some simple filtered query tests */
@@ -89,7 +89,7 @@
           new int[] {3});
   }
   public void testFQ4() throws Exception {
-    qtest(new FilteredQuery(qp.parse("xx^1000"),
+    qtest(new FilteredQuery(QueryBuilderHelper.newTermQuery(FIELD, "xx", 1000),
                             new ItemizedFilter(new int[] {1,3})),
           new int[] {3});
   }
@@ -162,14 +162,20 @@
   }
   public void testDMQ8() throws Exception {
     DisjunctionMaxQuery q = new DisjunctionMaxQuery(0.5f);
-    q.add(qp.parse("yy w5^100"));
-    q.add(qp.parse("xx^100000"));
+    q.add(new BooleanQueryBuilder(FIELD)
+        .addTermQuery("yy")
+        .addQuery(QueryBuilderHelper.newTermQuery(FIELD, "w5", 100))
+        .get());
+    q.add(QueryBuilderHelper.newTermQuery(FIELD, "xx", 100000));
     qtest(q, new int[] { 0,2,3 });
   }
   public void testDMQ9() throws Exception {
     DisjunctionMaxQuery q = new DisjunctionMaxQuery(0.5f);
-    q.add(qp.parse("yy w5^100"));
-    q.add(qp.parse("xx^0"));
+    q.add(new BooleanQueryBuilder(FIELD)
+        .addTermQuery("yy")
+        .addQuery(QueryBuilderHelper.newTermQuery(FIELD, "w5", 100))
+        .get());
+    q.add(QueryBuilderHelper.newTermQuery(FIELD, "xx", 0));
     qtest(q, new int[] { 0,2,3 });
   }
   
@@ -226,28 +232,109 @@
     qtest("yy +w3", new int[] { 0,1,2,3 });
   }
   public void testBQ4() throws Exception {
-    qtest("w1 (-xx w2)", new int[] { 0,1,2,3 });
+    BooleanQuery query = new BooleanQueryBuilder(FIELD)
+        .addTermQuery("w1")
+        .addQuery(new BooleanQueryBuilder(FIELD)
+            .addTermQuery("xx", BooleanClause.Occur.MUST_NOT)
+            .addTermQuery("w2")
+            .get())
+        .get();
+    qtest(query, new int[] { 0,1,2,3 });
   }
   public void testBQ5() throws Exception {
-    qtest("w1 (+qq w2)", new int[] { 0,1,2,3 });
+    BooleanQuery query = new BooleanQueryBuilder(FIELD)
+        .addTermQuery("w1")
+        .addQuery(new BooleanQueryBuilder(FIELD)
+            .addTermQuery("qq", BooleanClause.Occur.MUST)
+            .addTermQuery("w2")
+            .get())
+        .get();
+    qtest(query, new int[] { 0,1,2,3 });
   }
   public void testBQ6() throws Exception {
-    qtest("w1 -(-qq w5)", new int[] { 1,2,3 });
+    BooleanQuery query = new BooleanQueryBuilder(FIELD)
+        .addTermQuery("w1")
+        .addQuery(new BooleanQueryBuilder(FIELD)
+            .addTermQuery("qq", BooleanClause.Occur.MUST_NOT)
+            .addTermQuery("w5")
+            .get(), BooleanClause.Occur.MUST_NOT)
+        .get();
+    qtest(query, new int[] { 1,2,3 });
   }
   public void testBQ7() throws Exception {
-    qtest("+w1 +(qq (xx -w2) (+w3 +w4))", new int[] { 0 });
+    BooleanQuery query = new BooleanQueryBuilder(FIELD)
+        .addTermQuery("w1", BooleanClause.Occur.MUST)
+        .addQuery(new BooleanQueryBuilder(FIELD)
+            .addTermQuery("qq")
+            .addQuery(new BooleanQueryBuilder(FIELD)
+                .addTermQuery("xx")
+                .addTermQuery("w2", BooleanClause.Occur.MUST_NOT)
+                .get())
+            .addQuery(new BooleanQueryBuilder(FIELD)
+                .addTermQuery("w3", BooleanClause.Occur.MUST)
+                .addTermQuery("w4", BooleanClause.Occur.MUST)
+                .get())
+            .get(), BooleanClause.Occur.MUST)
+        .get();
+    qtest(query, new int[] { 0 });
   }
   public void testBQ8() throws Exception {
-    qtest("+w1 (qq (xx -w2) (+w3 +w4))", new int[] { 0,1,2,3 });
+    BooleanQuery query = new BooleanQueryBuilder(FIELD)
+        .addTermQuery("w1", BooleanClause.Occur.MUST)
+        .addQuery(new BooleanQueryBuilder(FIELD)
+            .addTermQuery("qq")
+            .addQuery(new BooleanQueryBuilder(FIELD)
+                .addTermQuery("xx")
+                .addTermQuery("w2", BooleanClause.Occur.MUST_NOT)
+                .get())
+            .addQuery(new BooleanQueryBuilder(FIELD)
+                .addTermQuery("w3", BooleanClause.Occur.MUST)
+                .addTermQuery("w4", BooleanClause.Occur.MUST)
+                .get())
+            .get())
+        .get();
+    qtest(query, new int[] { 0,1,2,3 });
   }
   public void testBQ9() throws Exception {
-    qtest("+w1 (qq (-xx w2) -(+w3 +w4))", new int[] { 0,1,2,3 });
+    BooleanQuery query = new BooleanQueryBuilder(FIELD)
+        .addTermQuery("w1", BooleanClause.Occur.MUST)
+        .addQuery(new BooleanQueryBuilder(FIELD)
+            .addTermQuery("qq")
+            .addQuery(new BooleanQueryBuilder(FIELD)
+                .addTermQuery("xx", BooleanClause.Occur.MUST_NOT)
+                .addTermQuery("w2")
+                .get())
+            .addQuery(new BooleanQueryBuilder(FIELD)
+                .addTermQuery("w3", BooleanClause.Occur.MUST)
+                .addTermQuery("w4", BooleanClause.Occur.MUST)
+                .get(), BooleanClause.Occur.MUST_NOT)
+            .get())
+        .get();
+    qtest(query, new int[] { 0,1,2,3 });
   }
   public void testBQ10() throws Exception {
-    qtest("+w1 +(qq (-xx w2) -(+w3 +w4))", new int[] { 1 });
+    BooleanQuery query = new BooleanQueryBuilder(FIELD)
+        .addTermQuery("w1", BooleanClause.Occur.MUST)
+        .addQuery(new BooleanQueryBuilder(FIELD)
+            .addTermQuery("qq")
+            .addQuery(new BooleanQueryBuilder(FIELD)
+                .addTermQuery("xx", BooleanClause.Occur.MUST_NOT)
+                .addTermQuery("w2")
+                .get())
+            .addQuery(new BooleanQueryBuilder(FIELD)
+                .addTermQuery("w3", BooleanClause.Occur.MUST)
+                .addTermQuery("w4", BooleanClause.Occur.MUST)
+                .get(), BooleanClause.Occur.MUST_NOT)
+            .get(), BooleanClause.Occur.MUST)
+        .get();
+    qtest(query, new int[] { 1 });
   }
   public void testBQ11() throws Exception {
-    qtest("w1 w2^1000.0", new int[] { 0,1,2,3 });
+    qtest(new BooleanQueryBuilder(FIELD)
+        .addTermQuery("w1")
+        .addQuery(QueryBuilderHelper.newTermQuery(FIELD, "w2", 1000))
+        .get(),
+        new int[] { 0,1,2,3 });
   }
   public void testBQ14() throws Exception {
     BooleanQuery q = new BooleanQuery(true);
@@ -302,49 +389,196 @@
     qtest("yy +alt:w3", new int[] { 0,1,2,3 });
   }
   public void testMultiFieldBQ4() throws Exception {
-    qtest("w1 (-xx alt:w2)", new int[] { 0,1,2,3 });
+    BooleanQuery query = new BooleanQueryBuilder(FIELD)
+        .addTermQuery("w1")
+        .addQuery(new BooleanQueryBuilder(FIELD)
+            .addTermQuery("xx", BooleanClause.Occur.MUST_NOT)
+            .addTermQuery("alt", "w2")
+            .get())
+        .get();
+    qtest(query, new int[] { 0,1,2,3 });
   }
   public void testMultiFieldBQ5() throws Exception {
-    qtest("w1 (+alt:qq alt:w2)", new int[] { 0,1,2,3 });
+    BooleanQuery query = new BooleanQueryBuilder(FIELD)
+        .addTermQuery("w1")
+        .addQuery(new BooleanQueryBuilder("alt")
+            .addTermQuery("qq", BooleanClause.Occur.MUST)
+            .addTermQuery("w2")
+            .get())
+        .get();
+    qtest(query, new int[] { 0,1,2,3 });
   }
   public void testMultiFieldBQ6() throws Exception {
-    qtest("w1 -(-alt:qq alt:w5)", new int[] { 1,2,3 });
+    BooleanQuery query = new BooleanQueryBuilder(FIELD)
+        .addTermQuery("w1")
+        .addQuery(new BooleanQueryBuilder("alt")
+            .addTermQuery("qq", BooleanClause.Occur.MUST_NOT)
+            .addTermQuery("w5")
+            .get(), BooleanClause.Occur.MUST_NOT)
+        .get();
+    qtest(query, new int[] { 1,2,3 });
   }
   public void testMultiFieldBQ7() throws Exception {
-    qtest("+w1 +(alt:qq (alt:xx -alt:w2) (+alt:w3 +alt:w4))", new int[] { 0 });
+    BooleanQuery query = new BooleanQueryBuilder(FIELD)
+        .addTermQuery("w1", BooleanClause.Occur.MUST)
+        .addQuery(new BooleanQueryBuilder("alt")
+            .addTermQuery("qq")
+            .addQuery(new BooleanQueryBuilder("alt")
+                .addTermQuery("xx")
+                .addTermQuery("w2", BooleanClause.Occur.MUST_NOT)
+                .get())
+            .addQuery(new BooleanQueryBuilder("alt")
+                .addTermQuery("w3", BooleanClause.Occur.MUST)
+                .addTermQuery("w4", BooleanClause.Occur.MUST)
+                .get())
+            .get(), BooleanClause.Occur.MUST)
+        .get();
+    qtest(query, new int[] { 0 });
   }
   public void testMultiFieldBQ8() throws Exception {
-    qtest("+alt:w1 (qq (alt:xx -w2) (+alt:w3 +w4))", new int[] { 0,1,2,3 });
+    BooleanQuery query = new BooleanQueryBuilder(FIELD)
+        .addTermQuery("alt", "w1", BooleanClause.Occur.MUST)
+        .addQuery(new BooleanQueryBuilder(FIELD)
+            .addTermQuery("qq")
+            .addQuery(new BooleanQueryBuilder(FIELD)
+                .addTermQuery("alt", "xx")
+                .addTermQuery("w2", BooleanClause.Occur.MUST_NOT)
+                .get())
+            .addQuery(new BooleanQueryBuilder(FIELD)
+                .addTermQuery("alt", "w3", BooleanClause.Occur.MUST)
+                .addTermQuery("w4", BooleanClause.Occur.MUST)
+                .get())
+            .get())
+        .get();
+    qtest(query, new int[] { 0,1,2,3 });
   }
   public void testMultiFieldBQ9() throws Exception {
-    qtest("+w1 (alt:qq (-xx w2) -(+alt:w3 +w4))", new int[] { 0,1,2,3 });
+    BooleanQuery query = new BooleanQueryBuilder(FIELD)
+        .addTermQuery("w1", BooleanClause.Occur.MUST)
+        .addQuery(new BooleanQueryBuilder("alt")
+            .addTermQuery("qq")
+            .addQuery(new BooleanQueryBuilder(FIELD)
+                .addTermQuery("xx", BooleanClause.Occur.MUST_NOT)
+                .addTermQuery("w2")
+                .get())
+            .addQuery(new BooleanQueryBuilder(FIELD)
+                .addTermQuery("alt", "w3", BooleanClause.Occur.MUST)
+                .addTermQuery("w4", BooleanClause.Occur.MUST)
+                .get(), BooleanClause.Occur.MUST_NOT)
+            .get())
+        .get();
+    qtest(query, new int[] { 0,1,2,3 });
   }
   public void testMultiFieldBQ10() throws Exception {
-    qtest("+w1 +(alt:qq (-xx alt:w2) -(+alt:w3 +w4))", new int[] { 1 });
+    BooleanQuery query = new BooleanQueryBuilder(FIELD)
+        .addTermQuery("w1", BooleanClause.Occur.MUST)
+        .addQuery(new BooleanQueryBuilder("alt")
+            .addTermQuery("qq")
+            .addQuery(new BooleanQueryBuilder(FIELD)
+                .addTermQuery("xx", BooleanClause.Occur.MUST_NOT)
+                .addTermQuery("w2")
+                .get())
+            .addQuery(new BooleanQueryBuilder(FIELD)
+                .addTermQuery("alt", "w3", BooleanClause.Occur.MUST)
+                .addTermQuery("w4", BooleanClause.Occur.MUST)
+                .get(), BooleanClause.Occur.MUST_NOT)
+            .get(), BooleanClause.Occur.MUST)
+        .get();
+    qtest(query, new int[] { 1 });
   }
 
   /* BQ of PQ: using alt so some fields have zero boost and some don't */
   
   public void testMultiFieldBQofPQ1() throws Exception {
-    qtest("\"w1 w2\" alt:\"w1 w2\"", new int[] { 0 });
+    BooleanQuery query = new BooleanQueryBuilder()
+        .addQuery(new PhraseQueryBuilder(FIELD)
+            .addTerm("w1")
+            .addTerm("w2")
+            .get())
+        .addQuery(new PhraseQueryBuilder("alt")
+            .addTerm("w1")
+            .addTerm("w2")
+            .get())
+        .get();
+    qtest(query, new int[] { 0 });
   }
   public void testMultiFieldBQofPQ2() throws Exception {
-    qtest("\"w1 w3\" alt:\"w1 w3\"", new int[] { 1,3 });
+    BooleanQuery query = new BooleanQueryBuilder()
+        .addQuery(new PhraseQueryBuilder(FIELD)
+            .addTerm("w1")
+            .addTerm("w3")
+            .get())
+        .addQuery(new PhraseQueryBuilder("alt")
+            .addTerm("w1")
+            .addTerm("w3")
+            .get())
+        .get();
+    qtest(query, new int[] { 1,3 });
   }
   public void testMultiFieldBQofPQ3() throws Exception {
-    qtest("\"w1 w2\"~1 alt:\"w1 w2\"~1", new int[] { 0,1,2 });
+    BooleanQuery query = new BooleanQueryBuilder()
+        .addQuery(new PhraseQueryBuilder(FIELD, 1)
+            .addTerm("w1")
+            .addTerm("w2")
+            .get())
+        .addQuery(new PhraseQueryBuilder("alt", 1)
+            .addTerm("w1")
+            .addTerm("w2")
+            .get())
+        .get();
+    qtest(query, new int[] { 0,1,2 });
   }
   public void testMultiFieldBQofPQ4() throws Exception {
-    qtest("\"w2 w3\"~1 alt:\"w2 w3\"~1", new int[] { 0,1,2,3 });
+    BooleanQuery query = new BooleanQueryBuilder()
+        .addQuery(new PhraseQueryBuilder(FIELD, 1)
+            .addTerm("w2")
+            .addTerm("w3")
+            .get())
+        .addQuery(new PhraseQueryBuilder("alt", 1)
+            .addTerm("w2")
+            .addTerm("w3")
+            .get())
+        .get();
+    qtest(query, new int[] { 0,1,2,3 });
   }
   public void testMultiFieldBQofPQ5() throws Exception {
-    qtest("\"w3 w2\"~1 alt:\"w3 w2\"~1", new int[] { 1,3 });
+    BooleanQuery query = new BooleanQueryBuilder()
+        .addQuery(new PhraseQueryBuilder(FIELD, 1)
+            .addTerm("w3")
+            .addTerm("w2")
+            .get())
+        .addQuery(new PhraseQueryBuilder("alt", 1)
+            .addTerm("w3")
+            .addTerm("w2")
+            .get())
+        .get();
+    qtest(query, new int[] { 1,3 });
   }
   public void testMultiFieldBQofPQ6() throws Exception {
-    qtest("\"w3 w2\"~2 alt:\"w3 w2\"~2", new int[] { 0,1,3 });
+    BooleanQuery query = new BooleanQueryBuilder()
+        .addQuery(new PhraseQueryBuilder(FIELD, 2)
+            .addTerm("w3")
+            .addTerm("w2")
+            .get())
+        .addQuery(new PhraseQueryBuilder("alt", 2)
+            .addTerm("w3")
+            .addTerm("w2")
+            .get())
+        .get();
+    qtest(query, new int[] { 0,1,3 });
   }
   public void testMultiFieldBQofPQ7() throws Exception {
-    qtest("\"w3 w2\"~3 alt:\"w3 w2\"~3", new int[] { 0,1,2,3 });
+    BooleanQuery query = new BooleanQueryBuilder()
+        .addQuery(new PhraseQueryBuilder(FIELD, 3)
+            .addTerm("w3")
+            .addTerm("w2")
+            .get())
+        .addQuery(new PhraseQueryBuilder("alt", 3)
+            .addTerm("w3")
+            .addTerm("w2")
+            .get())
+        .get();
+    qtest(query, new int[] { 0,1,2,3 });
   }
 
 }
Index: lucene/src/test-framework/org/apache/lucene/search/BooleanQueryBuilder.java
===================================================================
--- lucene/src/test-framework/org/apache/lucene/search/BooleanQueryBuilder.java	Mon Jul 04 16:06:23 NZST 2011
+++ lucene/src/test-framework/org/apache/lucene/search/BooleanQueryBuilder.java	Mon Jul 04 16:06:23 NZST 2011
@@ -0,0 +1,66 @@
+package org.apache.lucene.search;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.apache.lucene.index.Term;
+
+public class BooleanQueryBuilder {
+
+  private BooleanQuery query = new BooleanQuery();
+
+  private String defaultField;
+
+  public BooleanQueryBuilder(String defaultField) {
+    this.defaultField = defaultField;
+  }
+
+  public BooleanQueryBuilder() {
+  }
+
+  public BooleanQueryBuilder addTermQuery(String value) {
+    assert defaultField != null;
+    return this.addTermQuery(defaultField, value);
+  }
+
+  public BooleanQueryBuilder addTermQuery(String field, String value) {
+    return this.addTermQuery(field, value, BooleanClause.Occur.SHOULD);
+  }
+  
+  public BooleanQueryBuilder addTermQuery(String value, BooleanClause.Occur occur) {
+    assert defaultField != null;
+    return this.addTermQuery(defaultField, value, occur);
+  }
+
+  public BooleanQueryBuilder addTermQuery(String field, String value, BooleanClause.Occur occur) {
+    query.add(new TermQuery(new Term(field, value)), occur);
+    return this;
+  }
+
+  public BooleanQueryBuilder addQuery(Query query) {
+    return this.addQuery(query, BooleanClause.Occur.SHOULD);
+  }
+
+  public BooleanQueryBuilder addQuery(Query clauseQuery, BooleanClause.Occur occur) {
+    query.add(clauseQuery, occur);
+    return this;
+  }
+
+  public BooleanQuery get() {
+    return query;
+  }
+}
Index: lucene/src/test/org/apache/lucene/search/TestMatchAllDocsQuery.java
===================================================================
--- lucene/src/test/org/apache/lucene/search/TestMatchAllDocsQuery.java	(revision 1098303)
+++ lucene/src/test/org/apache/lucene/search/TestMatchAllDocsQuery.java	Mon Jul 04 20:27:21 NZST 2011
@@ -25,7 +25,6 @@
 import org.apache.lucene.index.IndexWriter;
 import org.apache.lucene.index.Term;
 import org.apache.lucene.index.IndexReader;
-import org.apache.lucene.queryParser.QueryParser;
 import org.apache.lucene.store.Directory;
 
 import org.apache.lucene.util.LuceneTestCase;
@@ -97,18 +96,6 @@
     hits = is.search(new MatchAllDocsQuery(), null, 1000).scoreDocs;
     assertEquals(2, hits.length);
     
-    // test parsable toString()
-    QueryParser qp = new QueryParser(TEST_VERSION_CURRENT, "key", analyzer);
-    hits = is.search(qp.parse(new MatchAllDocsQuery().toString()), null, 1000).scoreDocs;
-    assertEquals(2, hits.length);
-
-    // test parsable toString() with non default boost
-    Query maq = new MatchAllDocsQuery();
-    maq.setBoost(2.3f);
-    Query pq = qp.parse(maq.toString());
-    hits = is.search(pq, null, 1000).scoreDocs;
-    assertEquals(2, hits.length);
-    
     is.close();
     ir.close();
     dir.close();
Index: lucene/src/test/org/apache/lucene/search/TestComplexExplanations.java
===================================================================
--- lucene/src/test/org/apache/lucene/search/TestComplexExplanations.java	(revision 1140848)
+++ lucene/src/test/org/apache/lucene/search/TestComplexExplanations.java	Mon Jul 04 16:06:23 NZST 2011
@@ -17,9 +17,12 @@
  * limitations under the License.
  */
 
+import org.apache.lucene.index.Term;
 import org.apache.lucene.search.BooleanClause.Occur;
 import org.apache.lucene.search.spans.*;
 
+import static org.apache.lucene.search.QueryBuilderHelper.newTermQuery;
+
 /**
  * TestExplanations subclass that builds up super crazy complex queries
  * on the assumption that if the explanations work out right for them,
@@ -57,8 +60,12 @@
   public void test1() throws Exception {
     
     BooleanQuery q = new BooleanQuery();
-    
+
-    q.add(qp.parse("\"w1 w2\"~1"), Occur.MUST);
+    PhraseQuery phraseQuery = new PhraseQuery();
+    phraseQuery.setSlop(1);
+    phraseQuery.add(new Term(FIELD, "w1"));
+    phraseQuery.add(new Term(FIELD, "w2"));
+    q.add(phraseQuery, Occur.MUST);
     q.add(snear(st("w2"),
                 sor("w5","zz"),
                 4, true),
@@ -105,8 +112,12 @@
   public void test2() throws Exception {
     
     BooleanQuery q = new BooleanQuery();
-    
+
-    q.add(qp.parse("\"w1 w2\"~1"), Occur.MUST);
+    PhraseQuery phraseQuery = new PhraseQuery();
+    phraseQuery.setSlop(1);
+    phraseQuery.add(new Term(FIELD, "w1"));
+    phraseQuery.add(new Term(FIELD, "w2"));
+    q.add(phraseQuery, Occur.MUST);
     q.add(snear(st("w2"),
                 sor("w5","zz"),
                 4, true),
@@ -161,7 +172,7 @@
   // with scores of 0 wrapped in other queries
 
   public void testT3() throws Exception {
-    bqtest("w1^0.0", new int[] { 0,1,2,3 });
+    bqtest(newTermQuery(FIELD, "w1", 0), new int[] { 0,1,2,3 });
   }
 
   public void testMA3() throws Exception {
@@ -171,7 +182,7 @@
   }
   
   public void testFQ5() throws Exception {
-    bqtest(new FilteredQuery(qp.parse("xx^0"),
+    bqtest(new FilteredQuery(newTermQuery(FIELD, "xx", 0),
                              new ItemizedFilter(new int[] {1,3})),
            new int[] {3});
   }
@@ -184,8 +195,12 @@
   
   public void testDMQ10() throws Exception {
     DisjunctionMaxQuery q = new DisjunctionMaxQuery(0.5f);
-    q.add(qp.parse("yy w5^100"));
-    q.add(qp.parse("xx^0"));
+    BooleanQuery query = new BooleanQueryBuilder()
+        .addTermQuery(FIELD, "yy")
+        .addQuery(newTermQuery(FIELD, "w5", 100))
+        .get();
+    q.add(query);
+    q.add(newTermQuery(FIELD, "xx", 0));
     q.setBoost(0.0f);
     bqtest(q, new int[] { 0,2,3 });
   }
@@ -205,17 +220,35 @@
   }
   public void testBQ13() throws Exception {
     // NOTE: using qtest not bqtest
-    qtest("w1 -w5^0.0", new int[] { 1,2,3 });
+    BooleanQuery query = new BooleanQueryBuilder()
+        .addTermQuery(FIELD, "w1")
+        .addQuery(newTermQuery(FIELD, "w5", 0), Occur.MUST_NOT)
+        .get();
+    qtest(query, new int[] { 1,2,3 });
   }
   public void testBQ18() throws Exception {
     // NOTE: using qtest not bqtest
-    qtest("+w1^0.0 w2", new int[] { 0,1,2,3 });
+    BooleanQuery query = new BooleanQueryBuilder()
+        .addQuery(newTermQuery(FIELD, "w1", 0), Occur.MUST)
+        .addTermQuery(FIELD, "w2")
+        .get();
+    qtest(query, new int[] { 0,1,2,3 });
   }
   public void testBQ21() throws Exception {
-    bqtest("(+w1 w2)^0.0", new int[] { 0,1,2,3 });
+    BooleanQuery query = new BooleanQueryBuilder()
+        .addTermQuery(FIELD, "w1", Occur.MUST)
+        .addTermQuery(FIELD, "w2")
+        .get();
+    query.setBoost(0);
+    bqtest(query, new int[] { 0,1,2,3 });
   }
   public void testBQ22() throws Exception {
-    bqtest("(+w1^0.0 w2)^0.0", new int[] { 0,1,2,3 });
+    BooleanQuery query = new BooleanQueryBuilder()
+        .addQuery(newTermQuery(FIELD, "w1", 0), Occur.MUST)
+        .addTermQuery(FIELD, "w2")
+        .get();
+    query.setBoost(0);
+    bqtest(query, new int[] { 0,1,2,3 });
   }
 
   public void testST3() throws Exception {
Index: lucene/src/test/org/apache/lucene/TestDemo.java
===================================================================
--- lucene/src/test/org/apache/lucene/TestDemo.java	(revision 1091132)
+++ lucene/src/test/org/apache/lucene/TestDemo.java	Mon Jul 04 20:27:21 NZST 2011
@@ -25,12 +25,7 @@
 import org.apache.lucene.document.Field;
 import org.apache.lucene.index.Term;
 import org.apache.lucene.index.RandomIndexWriter;
-import org.apache.lucene.queryParser.ParseException;
-import org.apache.lucene.queryParser.QueryParser;
-import org.apache.lucene.search.TopDocs;
-import org.apache.lucene.search.IndexSearcher;
-import org.apache.lucene.search.Query;
-import org.apache.lucene.search.TermQuery;
+import org.apache.lucene.search.*;
 import org.apache.lucene.store.Directory;
 import org.apache.lucene.util.LuceneTestCase;
 
@@ -42,7 +37,7 @@
  */
 public class TestDemo extends LuceneTestCase {
 
-  public void testDemo() throws IOException, ParseException {
+  public void testDemo() throws IOException {
     Analyzer analyzer = new MockAnalyzer(random);
 
     // Store the index in memory:
@@ -63,9 +58,7 @@
     IndexSearcher isearcher = new IndexSearcher(directory, true); // read-only=true
 
     assertEquals(1, isearcher.search(new TermQuery(new Term("fieldname", longTerm)), 1).totalHits);
-    // Parse a simple query that searches for "text":
-    QueryParser parser = new QueryParser(TEST_VERSION_CURRENT, "fieldname", analyzer);
-    Query query = parser.parse("text");
+    Query query = new TermQuery(new Term("fieldname", "text"));
     TopDocs hits = isearcher.search(query, null, 1);
     assertEquals(1, hits.totalHits);
     // Iterate through the results:
@@ -75,8 +68,10 @@
     }
 
     // Test simple phrase query
-    query = parser.parse("\"to be\"");
-    assertEquals(1, isearcher.search(query, null, 1).totalHits);
+    PhraseQuery phraseQuery = new PhraseQuery();
+    phraseQuery.add(new Term("fieldname", "to"));
+    phraseQuery.add(new Term("fieldname", "be"));
+    assertEquals(1, isearcher.search(phraseQuery, null, 1).totalHits);
 
     isearcher.close();
     directory.close();
