lucene-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dna...@apache.org
Subject cvs commit: jakarta-lucene/src/test/org/apache/lucene/search TestMultiPhraseQuery.java
Date Wed, 19 Jan 2005 23:32:53 GMT
dnaber      2005/01/19 15:32:52

  Modified:    src/java/org/apache/lucene/search MultiPhraseQuery.java
               src/test/org/apache/lucene/search TestMultiPhraseQuery.java
  Log:
  fix for bug 33161 (UnsupportedOperationException for some combinations of BooleanQuery and
MultiPhraseQuery)
  PR: 33161
  Submitted by: Rhett Sutphin
  
  Revision  Changes    Path
  1.2       +7 -2      jakarta-lucene/src/java/org/apache/lucene/search/MultiPhraseQuery.java
  
  Index: MultiPhraseQuery.java
  ===================================================================
  RCS file: /home/cvs/jakarta-lucene/src/java/org/apache/lucene/search/MultiPhraseQuery.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- MultiPhraseQuery.java	10 Oct 2004 15:27:15 -0000	1.1
  +++ MultiPhraseQuery.java	19 Jan 2005 23:32:52 -0000	1.2
  @@ -225,7 +225,7 @@
       }
     }
   
  -  protected Weight createWeight(Searcher searcher) {
  +  public Query rewrite(IndexReader reader) {
       if (termArrays.size() == 1) {                 // optimize one-term case
         Term[] terms = (Term[])termArrays.get(0);
         BooleanQuery boq = new BooleanQuery();
  @@ -233,8 +233,13 @@
           boq.add(new TermQuery(terms[i]), BooleanClause.Occur.SHOULD);
         }
         boq.setBoost(getBoost());
  -      return boq.createWeight(searcher);
  +      return boq;
  +    } else {
  +      return this;
       }
  +  }
  +  
  +  protected Weight createWeight(Searcher searcher) {
       return new MultiPhraseWeight(searcher);
     }
   
  
  
  
  1.7       +38 -7     jakarta-lucene/src/test/org/apache/lucene/search/TestMultiPhraseQuery.java
  
  Index: TestMultiPhraseQuery.java
  ===================================================================
  RCS file: /home/cvs/jakarta-lucene/src/test/org/apache/lucene/search/TestMultiPhraseQuery.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- TestMultiPhraseQuery.java	24 Nov 2004 19:41:16 -0000	1.6
  +++ TestMultiPhraseQuery.java	19 Jan 2005 23:32:52 -0000	1.7
  @@ -39,13 +39,11 @@
    */
   public class TestMultiPhraseQuery extends TestCase
   {
  -    public TestMultiPhraseQuery(String name)
  -    {
  +    public TestMultiPhraseQuery(String name) {
           super(name);
       }
   
  -    public void testPhrasePrefix() throws IOException
  -    {
  +    public void testPhrasePrefix() throws IOException {
           RAMDirectory indexStore = new RAMDirectory();
           IndexWriter writer = new IndexWriter(indexStore, new SimpleAnalyzer(), true);
           add("blueberry pie", writer);
  @@ -128,10 +126,43 @@
   
       }
       
  -    private void add(String s, IndexWriter writer) throws IOException
  -    {
  +    private void add(String s, IndexWriter writer) throws IOException {
         Document doc = new Document();
         doc.add(new Field("body", s, Field.Store.YES, Field.Index.TOKENIZED));
         writer.addDocument(doc);
       }
  +    
  +    public void testBooleanQueryContainingSingleTermPrefixQuery() throws IOException {
  +      // this tests against bug 33161 (now fixed)
  +      // In order to cause the bug, the outer query must have more than one term 
  +      // and all terms required.
  +      // The contained PhraseMultiQuery must contain exactly one term array.
  +
  +      RAMDirectory indexStore = new RAMDirectory();
  +      IndexWriter writer = new IndexWriter(indexStore, new SimpleAnalyzer(), true);
  +      add("blueberry pie", writer);
  +      add("blueberry chewing gum", writer);
  +      add("blue raspberry pie", writer);
  +      writer.optimize();
  +      writer.close();
  +
  +      IndexSearcher searcher = new IndexSearcher(indexStore);
  +      // This query will be equivalent to +body:pie +body:"blue*"
  +      BooleanQuery q = new BooleanQuery();
  +      q.add(new TermQuery(new Term("body", "pie")), BooleanClause.Occur.MUST);
  +
  +      MultiPhraseQuery trouble = new MultiPhraseQuery();
  +      trouble.add(new Term[] {
  +          new Term("body", "blueberry"),
  +          new Term("body", "blue")
  +      });
  +      q.add(trouble, BooleanClause.Occur.MUST);
  +
  +      // exception will be thrown here without fix
  +      Hits hits = searcher.search(q);
  +
  +      assertEquals("Wrong number of hits", 2, hits.length());
  +      searcher.close();
  +  }
  +
   }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: lucene-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: lucene-dev-help@jakarta.apache.org


Mime
View raw message