lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From chr...@apache.org
Subject svn commit: r1143231 [1/2] - in /lucene/dev/trunk/lucene/src/test/org/apache/lucene: ./ index/values/ queryParser/ search/ search/spans/
Date Wed, 06 Jul 2011 00:08:08 GMT
Author: chrism
Date: Wed Jul  6 00:08:07 2011
New Revision: 1143231

URL: http://svn.apache.org/viewvc?rev=1143231&view=rev
Log:
LUCENE-3273: Converted all Lucene core tests away from using QueryParser

Added:
    lucene/dev/trunk/lucene/src/test/org/apache/lucene/queryParser/TestMultiPhraseQueryParsing.java
Modified:
    lucene/dev/trunk/lucene/src/test/org/apache/lucene/TestDemo.java
    lucene/dev/trunk/lucene/src/test/org/apache/lucene/TestSearch.java
    lucene/dev/trunk/lucene/src/test/org/apache/lucene/TestSearchForDuplicates.java
    lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/values/TestDocValuesIndexing.java
    lucene/dev/trunk/lucene/src/test/org/apache/lucene/queryParser/TestQueryParser.java
    lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/TestBoolean2.java
    lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/TestBooleanQuery.java
    lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/TestComplexExplanations.java
    lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/TestDateSort.java
    lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/TestExplanations.java
    lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/TestFuzzyQuery.java
    lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/TestMatchAllDocsQuery.java
    lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/TestMultiPhraseQuery.java
    lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/TestNot.java
    lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/TestPhraseQuery.java
    lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/TestPositionIncrement.java
    lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/TestSimpleExplanations.java
    lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/TestTimeLimitingCollector.java
    lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/TestWildcard.java
    lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/spans/TestNearSpansOrdered.java

Modified: lucene/dev/trunk/lucene/src/test/org/apache/lucene/TestDemo.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/test/org/apache/lucene/TestDemo.java?rev=1143231&r1=1143230&r2=1143231&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/test/org/apache/lucene/TestDemo.java (original)
+++ lucene/dev/trunk/lucene/src/test/org/apache/lucene/TestDemo.java Wed Jul  6 00:08:07 2011
@@ -25,12 +25,7 @@ import org.apache.lucene.document.Docume
 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 @@ import org.apache.lucene.util.LuceneTest
  */
 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 @@ public class TestDemo extends LuceneTest
     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 @@ public class TestDemo extends LuceneTest
     }
 
     // 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();

Modified: lucene/dev/trunk/lucene/src/test/org/apache/lucene/TestSearch.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/test/org/apache/lucene/TestSearch.java?rev=1143231&r1=1143230&r2=1143231&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/test/org/apache/lucene/TestSearch.java (original)
+++ lucene/dev/trunk/lucene/src/test/org/apache/lucene/TestSearch.java Wed Jul  6 00:08:07 2011
@@ -17,6 +17,8 @@ package org.apache.lucene;
  * limitations under the License.
  */
 
+import java.util.ArrayList;
+import java.util.List;
 import java.util.Random;
 import java.io.PrintWriter;
 import java.io.StringWriter;
@@ -30,7 +32,6 @@ import org.apache.lucene.document.*;
 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,24 +101,13 @@ public class TestSearch extends LuceneTe
 
       IndexSearcher searcher = new IndexSearcher(directory, true);
 
-      String[] queries = {
-        "a b",
-        "\"a b\"",
-        "\"a b c\"",
-        "a c",
-        "\"a c\"",
-        "\"a c e\"",
-      };
       ScoreDoc[] hits = null;
 
       Sort sort = new Sort(new SortField[] {
           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]);
+      for (Query query : buildQueries()) {
         out.println("Query: " + query.toString("contents"));
         if (VERBOSE) {
           System.out.println("TEST: query=" + query);
@@ -134,4 +124,42 @@ public class TestSearch extends LuceneTe
       searcher.close();
       directory.close();
   }
+
+  private List<Query> buildQueries() {
+    List<Query> queries = new ArrayList<Query>();
+
+    BooleanQuery booleanAB = new BooleanQuery();
+    booleanAB.add(new TermQuery(new Term("contents", "a")), BooleanClause.Occur.SHOULD);
+    booleanAB.add(new TermQuery(new Term("contents", "b")), BooleanClause.Occur.SHOULD);
+    queries.add(booleanAB);
+
+    PhraseQuery phraseAB = new PhraseQuery();
+    phraseAB.add(new Term("contents", "a"));
+    phraseAB.add(new Term("contents", "b"));
+    queries.add(phraseAB);
+
+    PhraseQuery phraseABC = new PhraseQuery();
+    phraseABC.add(new Term("contents", "a"));
+    phraseABC.add(new Term("contents", "b"));
+    phraseABC.add(new Term("contents", "c"));
+    queries.add(phraseABC);
+
+    BooleanQuery booleanAC = new BooleanQuery();
+    booleanAC.add(new TermQuery(new Term("contents", "a")), BooleanClause.Occur.SHOULD);
+    booleanAC.add(new TermQuery(new Term("contents", "c")), BooleanClause.Occur.SHOULD);
+    queries.add(booleanAC);
+
+    PhraseQuery phraseAC = new PhraseQuery();
+    phraseAC.add(new Term("contents", "a"));
+    phraseAC.add(new Term("contents", "c"));
+    queries.add(phraseAC);
+
+    PhraseQuery phraseACE = new PhraseQuery();
+    phraseACE.add(new Term("contents", "a"));
+    phraseACE.add(new Term("contents", "c"));
+    phraseACE.add(new Term("contents", "e"));
+    queries.add(phraseACE);
+
+    return queries;
+  }
 }

Modified: lucene/dev/trunk/lucene/src/test/org/apache/lucene/TestSearchForDuplicates.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/test/org/apache/lucene/TestSearchForDuplicates.java?rev=1143231&r1=1143230&r2=1143231&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/test/org/apache/lucene/TestSearchForDuplicates.java (original)
+++ lucene/dev/trunk/lucene/src/test/org/apache/lucene/TestSearchForDuplicates.java Wed Jul  6 00:08:07 2011
@@ -27,7 +27,6 @@ import org.apache.lucene.document.*;
 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 @@ public class TestSearchForDuplicates ext
       // 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,12 +121,12 @@ public class TestSearchForDuplicates ext
       searcher = new IndexSearcher(directory, true);
       hits = null;
 
-      parser = new QueryParser(TEST_VERSION_CURRENT, PRIORITY_FIELD, analyzer);
-
-      query = parser.parse(HIGH_PRIORITY + " OR " + MED_PRIORITY);
-      out.println("Query: " + query.toString(PRIORITY_FIELD));
+      BooleanQuery booleanQuery = new BooleanQuery();
+      booleanQuery.add(new TermQuery(new Term(PRIORITY_FIELD, HIGH_PRIORITY)), BooleanClause.Occur.SHOULD);
+      booleanQuery.add(new TermQuery(new Term(PRIORITY_FIELD, MED_PRIORITY)), BooleanClause.Occur.SHOULD);
+      out.println("Query: " + booleanQuery.toString(PRIORITY_FIELD));
 
-      hits = searcher.search(query, null, MAX_DOCS, sort).scoreDocs;
+      hits = searcher.search(booleanQuery, null, MAX_DOCS, sort).scoreDocs;
       printHits(out, hits, searcher);
       checkHits(hits, MAX_DOCS, searcher);
 

Modified: lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/values/TestDocValuesIndexing.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/values/TestDocValuesIndexing.java?rev=1143231&r1=1143230&r2=1143231&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/values/TestDocValuesIndexing.java (original)
+++ lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/values/TestDocValuesIndexing.java Wed Jul  6 00:08:07 2011
@@ -42,11 +42,7 @@ import org.apache.lucene.index.Term;
 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.ScoreDoc;
-import org.apache.lucene.search.TopDocs;
+import org.apache.lucene.search.*;
 import org.apache.lucene.store.Directory;
 import org.apache.lucene.store.LockObtainFailedException;
 import org.apache.lucene.util.BytesRef;
@@ -77,8 +73,7 @@ public class TestDocValuesIndexing exten
   /*
    * 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 +93,15 @@ public class TestDocValuesIndexing exten
     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);
+
+    BooleanQuery query = new BooleanQuery();
+    query.add(new TermQuery(new Term("docId", "0")), BooleanClause.Occur.SHOULD);
+    query.add(new TermQuery(new Term("docId", "1")), BooleanClause.Occur.SHOULD);
+    query.add(new TermQuery(new Term("docId", "2")), BooleanClause.Occur.SHOULD);
+    query.add(new TermQuery(new Term("docId", "3")), BooleanClause.Occur.SHOULD);
+    query.add(new TermQuery(new Term("docId", "4")), BooleanClause.Occur.SHOULD);
+
+    TopDocs search = searcher.search(query, 10);
     assertEquals(5, search.totalHits);
     ScoreDoc[] scoreDocs = search.scoreDocs;
     IndexDocValues docValues = MultiPerDocValues.getPerDocs(reader).docValues("docId");

Added: lucene/dev/trunk/lucene/src/test/org/apache/lucene/queryParser/TestMultiPhraseQueryParsing.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/test/org/apache/lucene/queryParser/TestMultiPhraseQueryParsing.java?rev=1143231&view=auto
==============================================================================
--- lucene/dev/trunk/lucene/src/test/org/apache/lucene/queryParser/TestMultiPhraseQueryParsing.java (added)
+++ lucene/dev/trunk/lucene/src/test/org/apache/lucene/queryParser/TestMultiPhraseQueryParsing.java Wed Jul  6 00:08:07 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);
+  }
+
+}

Modified: lucene/dev/trunk/lucene/src/test/org/apache/lucene/queryParser/TestQueryParser.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/test/org/apache/lucene/queryParser/TestQueryParser.java?rev=1143231&r1=1143230&r2=1143231&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/test/org/apache/lucene/queryParser/TestQueryParser.java (original)
+++ lucene/dev/trunk/lucene/src/test/org/apache/lucene/queryParser/TestQueryParser.java Wed Jul  6 00:08:07 2011
@@ -19,7 +19,6 @@ package org.apache.lucene.queryParser;
 
 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.document.Field;
 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,96 @@ public class TestQueryParser extends Luc
     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));
+
+    PhraseQuery phraseQuery = new PhraseQuery();
+    phraseQuery.add(new Term("field", "1"));
+    phraseQuery.add(new Term("field", "2"));
+
+    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 = new PhraseQuery();
+    phraseQuery.add(new Term("field", "1"));
+    phraseQuery.add(new Term("field", "2"), 2);
+    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()));
+  }
+  
 }

Modified: lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/TestBoolean2.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/TestBoolean2.java?rev=1143231&r1=1143230&r2=1143231&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/TestBoolean2.java (original)
+++ lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/TestBoolean2.java Wed Jul  6 00:08:07 2011
@@ -26,8 +26,6 @@ import org.apache.lucene.document.Field;
 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,16 +115,7 @@ public class TestBoolean2 extends Lucene
     "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 void queriesTest(String queryText, int[] expDocNrs) throws Exception {
-//System.out.println();
-//System.out.println("Query: " + queryText);
-
-    Query query = makeQuery(queryText);
+  public void queriesTest(Query query, int[] expDocNrs) throws Exception {
     TopScoreDocCollector collector = TopScoreDocCollector.create(1000, false);
     searcher.search(query, null, collector);
     ScoreDoc[] hits1 = collector.topDocs().scoreDocs;
@@ -143,70 +132,98 @@ public class TestBoolean2 extends Lucene
 
   @Test
   public void testQueries01() throws Exception {
-    String queryText = "+w3 +xx";
+    BooleanQuery query = new BooleanQuery();
+    query.add(new TermQuery(new Term(field, "w3")), BooleanClause.Occur.MUST);
+    query.add(new TermQuery(new Term(field, "xx")), BooleanClause.Occur.MUST);
     int[] expDocNrs = {2,3};
-    queriesTest(queryText, expDocNrs);
+    queriesTest(query, expDocNrs);
   }
 
   @Test
   public void testQueries02() throws Exception {
-    String queryText = "+w3 xx";
+    BooleanQuery query = new BooleanQuery();
+    query.add(new TermQuery(new Term(field, "w3")), BooleanClause.Occur.MUST);
+    query.add(new TermQuery(new Term(field, "xx")), BooleanClause.Occur.SHOULD);
     int[] expDocNrs = {2,3,1,0};
-    queriesTest(queryText, expDocNrs);
+    queriesTest(query, expDocNrs);
   }
 
   @Test
   public void testQueries03() throws Exception {
-    String queryText = "w3 xx";
+    BooleanQuery query = new BooleanQuery();
+    query.add(new TermQuery(new Term(field, "w3")), BooleanClause.Occur.SHOULD);
+    query.add(new TermQuery(new Term(field, "xx")), BooleanClause.Occur.SHOULD);
     int[] expDocNrs = {2,3,1,0};
-    queriesTest(queryText, expDocNrs);
+    queriesTest(query, expDocNrs);
   }
 
   @Test
   public void testQueries04() throws Exception {
-    String queryText = "w3 -xx";
+    BooleanQuery query = new BooleanQuery();
+    query.add(new TermQuery(new Term(field, "w3")), BooleanClause.Occur.SHOULD);
+    query.add(new TermQuery(new Term(field, "xx")), BooleanClause.Occur.MUST_NOT);
     int[] expDocNrs = {1,0};
-    queriesTest(queryText, expDocNrs);
+    queriesTest(query, expDocNrs);
   }
 
   @Test
   public void testQueries05() throws Exception {
-    String queryText = "+w3 -xx";
+    BooleanQuery query = new BooleanQuery();
+    query.add(new TermQuery(new Term(field, "w3")), BooleanClause.Occur.MUST);
+    query.add(new TermQuery(new Term(field, "xx")), BooleanClause.Occur.MUST_NOT);
     int[] expDocNrs = {1,0};
-    queriesTest(queryText, expDocNrs);
+    queriesTest(query, expDocNrs);
   }
 
   @Test
   public void testQueries06() throws Exception {
-    String queryText = "+w3 -xx -w5";
+    BooleanQuery query = new BooleanQuery();
+    query.add(new TermQuery(new Term(field, "w3")), BooleanClause.Occur.MUST);
+    query.add(new TermQuery(new Term(field, "xx")), BooleanClause.Occur.MUST_NOT);
+    query.add(new TermQuery(new Term(field, "w5")), BooleanClause.Occur.MUST_NOT);
     int[] expDocNrs = {1};
-    queriesTest(queryText, expDocNrs);
+    queriesTest(query, expDocNrs);
   }
 
   @Test
   public void testQueries07() throws Exception {
-    String queryText = "-w3 -xx -w5";
+    BooleanQuery query = new BooleanQuery();
+    query.add(new TermQuery(new Term(field, "w3")), BooleanClause.Occur.MUST_NOT);
+    query.add(new TermQuery(new Term(field, "xx")), BooleanClause.Occur.MUST_NOT);
+    query.add(new TermQuery(new Term(field, "w5")), BooleanClause.Occur.MUST_NOT);
     int[] expDocNrs = {};
-    queriesTest(queryText, expDocNrs);
+    queriesTest(query, expDocNrs);
   }
 
   @Test
   public void testQueries08() throws Exception {
-    String queryText = "+w3 xx -w5";
+    BooleanQuery query = new BooleanQuery();
+    query.add(new TermQuery(new Term(field, "w3")), BooleanClause.Occur.MUST);
+    query.add(new TermQuery(new Term(field, "xx")), BooleanClause.Occur.SHOULD);
+    query.add(new TermQuery(new Term(field, "w5")), BooleanClause.Occur.MUST_NOT);
     int[] expDocNrs = {2,3,1};
-    queriesTest(queryText, expDocNrs);
+    queriesTest(query, expDocNrs);
   }
 
   @Test
   public void testQueries09() throws Exception {
-    String queryText = "+w3 +xx +w2 zz";
+    BooleanQuery query = new BooleanQuery();
+    query.add(new TermQuery(new Term(field, "w3")), BooleanClause.Occur.MUST);
+    query.add(new TermQuery(new Term(field, "xx")), BooleanClause.Occur.MUST);
+    query.add(new TermQuery(new Term(field, "w2")), BooleanClause.Occur.MUST);
+    query.add(new TermQuery(new Term(field, "zz")), BooleanClause.Occur.SHOULD);
     int[] expDocNrs = {2, 3};
-    queriesTest(queryText, expDocNrs);
+    queriesTest(query, expDocNrs);
   }
 
   @Test
   public void testQueries10() throws Exception {
-    String queryText = "+w3 +xx +w2 zz";
+    BooleanQuery query = new BooleanQuery();
+    query.add(new TermQuery(new Term(field, "w3")), BooleanClause.Occur.MUST);
+    query.add(new TermQuery(new Term(field, "xx")), BooleanClause.Occur.MUST);
+    query.add(new TermQuery(new Term(field, "w2")), BooleanClause.Occur.MUST);
+    query.add(new TermQuery(new Term(field, "zz")), BooleanClause.Occur.SHOULD);
+
     int[] expDocNrs = {2, 3};
     SimilarityProvider oldSimilarity = searcher.getSimilarityProvider();
     try {
@@ -216,7 +233,7 @@ public class TestBoolean2 extends Lucene
           return overlap / ((float)maxOverlap - 1);
         }
       });
-      queriesTest(queryText, expDocNrs);
+      queriesTest(query, expDocNrs);
     } finally {
       searcher.setSimilarityProvider(oldSimilarity);
     }

Modified: lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/TestBooleanQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/TestBooleanQuery.java?rev=1143231&r1=1143230&r2=1143231&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/TestBooleanQuery.java (original)
+++ lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/TestBooleanQuery.java Wed Jul  6 00:08:07 2011
@@ -28,7 +28,6 @@ import org.apache.lucene.index.IndexRead
 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 @@ public class TestBooleanQuery extends Lu
     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);
 

Modified: lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/TestComplexExplanations.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/TestComplexExplanations.java?rev=1143231&r1=1143230&r2=1143231&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/TestComplexExplanations.java (original)
+++ lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/TestComplexExplanations.java Wed Jul  6 00:08:07 2011
@@ -17,6 +17,7 @@ package org.apache.lucene.search;
  * limitations under the License.
  */
 
+import org.apache.lucene.index.Term;
 import org.apache.lucene.search.BooleanClause.Occur;
 import org.apache.lucene.search.spans.*;
 
@@ -57,8 +58,12 @@ public class TestComplexExplanations ext
   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),
@@ -66,7 +71,7 @@ public class TestComplexExplanations ext
     q.add(snear(sf("w3",2), st("w2"), st("w3"), 5, true),
           Occur.SHOULD);
     
-    Query t = new FilteredQuery(qp.parse("xx"),
+    Query t = new FilteredQuery(new TermQuery(new Term(FIELD, "xx")),
                                 new ItemizedFilter(new int[] {1,3}));
     t.setBoost(1000);
     q.add(t, Occur.SHOULD);
@@ -79,14 +84,25 @@ public class TestComplexExplanations ext
     dm.add(snear(st("w2"),
                  sor("w5","zz"),
                  4, true));
-    dm.add(qp.parse("QQ"));
-    dm.add(qp.parse("xx yy -zz"));
-    dm.add(qp.parse("-xx -w1"));
+    dm.add(new TermQuery(new Term(FIELD, "QQ")));
+
+    BooleanQuery xxYYZZ = new BooleanQuery();
+    xxYYZZ.add(new TermQuery(new Term(FIELD, "xx")), Occur.SHOULD);
+    xxYYZZ.add(new TermQuery(new Term(FIELD, "yy")), Occur.SHOULD);
+    xxYYZZ.add(new TermQuery(new Term(FIELD, "zz")), Occur.MUST_NOT);
+
+    dm.add(xxYYZZ);
+
+    BooleanQuery xxW1 = new BooleanQuery();
+    xxW1.add(new TermQuery(new Term(FIELD, "xx")), Occur.MUST_NOT);
+    xxW1.add(new TermQuery(new Term(FIELD, "w1")), Occur.MUST_NOT);
+
+    dm.add(xxW1);
 
     DisjunctionMaxQuery dm2 = new DisjunctionMaxQuery(0.5f);
-    dm2.add(qp.parse("w1"));
-    dm2.add(qp.parse("w2"));
-    dm2.add(qp.parse("w3"));
+    dm2.add(new TermQuery(new Term(FIELD, "w1")));
+    dm2.add(new TermQuery(new Term(FIELD, "w2")));
+    dm2.add(new TermQuery(new Term(FIELD, "w3")));
     dm.add(dm2);
 
     q.add(dm, Occur.SHOULD);
@@ -105,8 +121,12 @@ public class TestComplexExplanations ext
   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),
@@ -114,7 +134,7 @@ public class TestComplexExplanations ext
     q.add(snear(sf("w3",2), st("w2"), st("w3"), 5, true),
           Occur.SHOULD);
     
-    Query t = new FilteredQuery(qp.parse("xx"),
+    Query t = new FilteredQuery(new TermQuery(new Term(FIELD, "xx")),
                                 new ItemizedFilter(new int[] {1,3}));
     t.setBoost(1000);
     q.add(t, Occur.SHOULD);
@@ -127,14 +147,25 @@ public class TestComplexExplanations ext
     dm.add(snear(st("w2"),
                  sor("w5","zz"),
                  4, true));
-    dm.add(qp.parse("QQ"));
-    dm.add(qp.parse("xx yy -zz"));
-    dm.add(qp.parse("-xx -w1"));
+    dm.add(new TermQuery(new Term(FIELD, "QQ")));
+
+    BooleanQuery xxYYZZ = new BooleanQuery();
+    xxYYZZ.add(new TermQuery(new Term(FIELD, "xx")), Occur.SHOULD);
+    xxYYZZ.add(new TermQuery(new Term(FIELD, "yy")), Occur.SHOULD);
+    xxYYZZ.add(new TermQuery(new Term(FIELD, "zz")), Occur.MUST_NOT);
+
+    dm.add(xxYYZZ);
+
+    BooleanQuery xxW1 = new BooleanQuery();
+    xxW1.add(new TermQuery(new Term(FIELD, "xx")), Occur.MUST_NOT);
+    xxW1.add(new TermQuery(new Term(FIELD, "w1")), Occur.MUST_NOT);
+
+    dm.add(xxW1);
 
     DisjunctionMaxQuery dm2 = new DisjunctionMaxQuery(0.5f);
-    dm2.add(qp.parse("w1"));
-    dm2.add(qp.parse("w2"));
-    dm2.add(qp.parse("w3"));
+    dm2.add(new TermQuery(new Term(FIELD, "w1")));
+    dm2.add(new TermQuery(new Term(FIELD, "w2")));
+    dm2.add(new TermQuery(new Term(FIELD, "w3")));
     dm.add(dm2);
 
     q.add(dm, Occur.SHOULD);
@@ -161,7 +192,9 @@ public class TestComplexExplanations ext
   // with scores of 0 wrapped in other queries
 
   public void testT3() throws Exception {
-    bqtest("w1^0.0", new int[] { 0,1,2,3 });
+    TermQuery query = new TermQuery(new Term(FIELD, "w1"));
+    query.setBoost(0);
+    bqtest(query, new int[] { 0,1,2,3 });
   }
 
   public void testMA3() throws Exception {
@@ -171,7 +204,9 @@ public class TestComplexExplanations ext
   }
   
   public void testFQ5() throws Exception {
-    bqtest(new FilteredQuery(qp.parse("xx^0"),
+    TermQuery query = new TermQuery(new Term(FIELD, "xx"));
+    query.setBoost(0);
+    bqtest(new FilteredQuery(query,
                              new ItemizedFilter(new int[] {1,3})),
            new int[] {3});
   }
@@ -184,8 +219,19 @@ public class TestComplexExplanations ext
   
   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 BooleanQuery();
+    query.add(new TermQuery(new Term(FIELD, "yy")), Occur.SHOULD);
+    TermQuery boostedQuery = new TermQuery(new Term(FIELD, "w5"));
+    boostedQuery.setBoost(100);
+    query.add(boostedQuery, Occur.SHOULD);
+
+    q.add(query);
+
+    TermQuery xxBoostedQuery = new TermQuery(new Term(FIELD, "xx"));
+    xxBoostedQuery.setBoost(0);
+
+    q.add(xxBoostedQuery);
     q.setBoost(0.0f);
     bqtest(q, new int[] { 0,2,3 });
   }
@@ -201,21 +247,51 @@ public class TestComplexExplanations ext
   
   public void testBQ12() throws Exception {
     // NOTE: using qtest not bqtest
-    qtest("w1 w2^0.0", new int[] { 0,1,2,3 });
+    BooleanQuery query = new BooleanQuery();
+    query.add(new TermQuery(new Term(FIELD, "w1")), Occur.SHOULD);
+    TermQuery boostedQuery = new TermQuery(new Term(FIELD, "w2"));
+    boostedQuery.setBoost(0);
+    query.add(boostedQuery, Occur.SHOULD);
+    
+    qtest(query, new int[] { 0,1,2,3 });
   }
   public void testBQ13() throws Exception {
     // NOTE: using qtest not bqtest
-    qtest("w1 -w5^0.0", new int[] { 1,2,3 });
+    BooleanQuery query = new BooleanQuery();
+    query.add(new TermQuery(new Term(FIELD, "w1")), Occur.SHOULD);
+    TermQuery boostedQuery = new TermQuery(new Term(FIELD, "w5"));
+    boostedQuery.setBoost(0);
+    query.add(boostedQuery, Occur.MUST_NOT);
+
+    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 BooleanQuery();
+    TermQuery boostedQuery = new TermQuery(new Term(FIELD, "w1"));
+    boostedQuery.setBoost(0);
+    query.add(boostedQuery, Occur.MUST);
+    query.add(new TermQuery(new Term(FIELD, "w2")), Occur.SHOULD);
+    
+    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 BooleanQuery();
+    query.add(new TermQuery(new Term(FIELD, "w1")), Occur.MUST);
+    query.add(new TermQuery(new Term(FIELD, "w2")), Occur.SHOULD);
+    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 BooleanQuery();
+    TermQuery boostedQuery = new TermQuery(new Term(FIELD, "w1"));
+    boostedQuery.setBoost(0);
+    query.add(boostedQuery, Occur.MUST);
+    query.add(new TermQuery(new Term(FIELD, "w2")), Occur.SHOULD);
+    query.setBoost(0);
+
+    bqtest(query, new int[] { 0,1,2,3 });
   }
 
   public void testST3() throws Exception {

Modified: lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/TestDateSort.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/TestDateSort.java?rev=1143231&r1=1143230&r2=1143231&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/TestDateSort.java (original)
+++ lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/TestDateSort.java Wed Jul  6 00:08:07 2011
@@ -19,6 +19,7 @@ package org.apache.lucene.search;
 
 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.Docume
 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,9 +80,7 @@ public class TestDateSort extends Lucene
     IndexSearcher searcher = newSearcher(reader);
 
     Sort sort = new Sort(new SortField(DATE_TIME_FIELD, SortField.Type.STRING, true));
-
-    QueryParser queryParser = new QueryParser(TEST_VERSION_CURRENT, TEXT_FIELD, new MockAnalyzer(random));
-    Query query = queryParser.parse("Document");
+    Query query = new TermQuery(new Term(TEXT_FIELD, "document"));
 
     // Execute the search and process the search results.
     String[] actualOrder = new String[5];

Modified: lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/TestExplanations.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/TestExplanations.java?rev=1143231&r1=1143230&r2=1143231&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/TestExplanations.java (original)
+++ lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/TestExplanations.java Wed Jul  6 00:08:07 2011
@@ -17,8 +17,6 @@ package org.apache.lucene.search;
  * 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,6 @@ public class TestExplanations extends Lu
   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));
   
   @AfterClass
   public static void afterClassTestExplanations() throws Exception {
@@ -95,15 +91,6 @@ public class TestExplanations extends Lu
     "w1 xx w2 yy w3",
     "w1 w3 xx w2 yy w3 zz"
   };
-
-  public Query makeQuery(String queryText) throws ParseException {
-    return qp.parse(queryText);
-  }
-
-  /** check the expDocNrs first, then check the query (and the explanations) */
-  public void qtest(String queryText, int[] expDocNrs) throws Exception {
-    qtest(makeQuery(queryText), expDocNrs);
-  }
   
   /** check the expDocNrs first, then check the query (and the explanations) */
   public void qtest(Query q, int[] expDocNrs) throws Exception {
@@ -120,15 +107,6 @@ public class TestExplanations extends Lu
     qtest(reqB(q), expDocNrs);
     qtest(optB(q), expDocNrs);
   }
-  /**
-   * Tests a query using qtest after wrapping it with both optB and reqB
-   * @see #qtest
-   * @see #reqB
-   * @see #optB
-   */
-  public void bqtest(String queryText, int[] expDocNrs) throws Exception {
-    bqtest(makeQuery(queryText), expDocNrs);
-  }
   
   /** 
    * Convenience subclass of FieldCacheTermsFilter
@@ -217,27 +195,13 @@ public class TestExplanations extends Lu
    * MACRO: Wraps a Query in a BooleanQuery so that it is optional, along
    * with a second prohibited clause which will never match anything
    */
-  public Query optB(String q) throws Exception {
-    return optB(makeQuery(q));
-  }
-  /**
-   * MACRO: Wraps a Query in a BooleanQuery so that it is optional, along
-   * with a second prohibited clause which will never match anything
-   */
   public Query optB(Query q) throws Exception {
     BooleanQuery bq = new BooleanQuery(true);
     bq.add(q, BooleanClause.Occur.SHOULD);
     bq.add(new TermQuery(new Term("NEVER","MATCH")), BooleanClause.Occur.MUST_NOT);
     return bq;
   }
-  
-  /**
-   * MACRO: Wraps a Query in a BooleanQuery so that it is required, along
-   * with a second optional clause which will match everything
-   */
-  public Query reqB(String q) throws Exception {
-    return reqB(makeQuery(q));
-  }
+
   /**
    * MACRO: Wraps a Query in a BooleanQuery so that it is required, along
    * with a second optional clause which will match everything

Modified: lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/TestFuzzyQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/TestFuzzyQuery.java?rev=1143231&r1=1143230&r2=1143231&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/TestFuzzyQuery.java (original)
+++ lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/TestFuzzyQuery.java Wed Jul  6 00:08:07 2011
@@ -28,7 +28,6 @@ import org.apache.lucene.index.IndexRead
 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 @@ public class TestFuzzyQuery extends Luce
     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 @@ public class TestFuzzyQuery extends Luce
     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 @@ public class TestFuzzyQuery extends Luce
     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"));

Modified: lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/TestMatchAllDocsQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/TestMatchAllDocsQuery.java?rev=1143231&r1=1143230&r2=1143231&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/TestMatchAllDocsQuery.java (original)
+++ lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/TestMatchAllDocsQuery.java Wed Jul  6 00:08:07 2011
@@ -25,7 +25,6 @@ import org.apache.lucene.document.Field;
 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 @@ public class TestMatchAllDocsQuery exten
     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();

Modified: lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/TestMultiPhraseQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/TestMultiPhraseQuery.java?rev=1143231&r1=1143230&r2=1143231&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/TestMultiPhraseQuery.java (original)
+++ lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/TestMultiPhraseQuery.java Wed Jul  6 00:08:07 2011
@@ -24,7 +24,6 @@ import org.apache.lucene.index.TermsEnum
 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 @@ public class TestMultiPhraseQuery extend
    * 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);
   }
   

Modified: lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/TestNot.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/TestNot.java?rev=1143231&r1=1143230&r2=1143231&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/TestNot.java (original)
+++ lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/TestNot.java Wed Jul  6 00:08:07 2011
@@ -17,11 +17,11 @@ package org.apache.lucene.search;
  * limitations under the License.
  */
 
+import org.apache.lucene.index.Term;
 import org.apache.lucene.util.LuceneTestCase;
 
 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 +44,11 @@ public class TestNot extends LuceneTestC
     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);
+
+    BooleanQuery query = new BooleanQuery();
+    query.add(new TermQuery(new Term("field", "a")), BooleanClause.Occur.SHOULD);
+    query.add(new TermQuery(new Term("field", "b")), BooleanClause.Occur.MUST_NOT);
+
     ScoreDoc[] hits = searcher.search(query, null, 1000).scoreDocs;
     assertEquals(0, hits.length);
     writer.close();

Modified: lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/TestPhraseQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/TestPhraseQuery.java?rev=1143231&r1=1143230&r2=1143231&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/TestPhraseQuery.java (original)
+++ lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/TestPhraseQuery.java Wed Jul  6 00:08:07 2011
@@ -23,7 +23,6 @@ import org.apache.lucene.analysis.tokena
 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 class TestPhraseQuery extends Luc
   }
   
   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());

Modified: lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/TestPositionIncrement.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/TestPositionIncrement.java?rev=1143231&r1=1143230&r2=1143231&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/TestPositionIncrement.java (original)
+++ lucene/dev/trunk/lucene/src/test/org/apache/lucene/search/TestPositionIncrement.java Wed Jul  6 00:08:07 2011
@@ -37,7 +37,6 @@ import org.apache.lucene.index.IndexRead
 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,38 +192,6 @@ public class TestPositionIncrement exten
     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();
@@ -323,4 +290,4 @@ public class TestPositionIncrement exten
     is.getIndexReader().close();
     dir.close();
   }
-}
\ No newline at end of file
+}



Mime
View raw message