lucene-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From o...@apache.org
Subject cvs commit: jakarta-lucene/src/test/org/apache/lucene/search TestPhrasePrefixQuery.java
Date Thu, 01 May 2003 00:40:41 GMT
otis        2003/04/30 17:40:41

  Modified:    src/test/org/apache/lucene/search TestPhrasePrefixQuery.java
  Log:
  - Fixed a bug that allowed queries to retrieve extra matches.
  - Fixed indentation that was all messed up, and some spelling mistakes.
  
  Revision  Changes    Path
  1.2       +35 -27    jakarta-lucene/src/test/org/apache/lucene/search/TestPhrasePrefixQuery.java
  
  Index: TestPhrasePrefixQuery.java
  ===================================================================
  RCS file: /home/cvs/jakarta-lucene/src/test/org/apache/lucene/search/TestPhrasePrefixQuery.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- TestPhrasePrefixQuery.java	18 Jul 2002 14:39:58 -0000	1.1
  +++ TestPhrasePrefixQuery.java	1 May 2003 00:40:41 -0000	1.2
  @@ -80,7 +80,7 @@
   {
       public TestPhrasePrefixQuery(String name)
       {
  -	super(name);
  +        super(name);
       }
   
       /**
  @@ -94,41 +94,49 @@
           Document doc1 = new Document();
           Document doc2 = new Document();
           Document doc3 = new Document();
  -	Document doc4 = new Document();
  -	doc1.add(Field.Text("body", "blueberry pie"));
  -        doc2.add(Field.Text("body", "blueberry pizza"));
  -        doc3.add(Field.Text("body", "blueberry chewing gum"));
  -        doc4.add(Field.Text("body", "picadelly circus"));
  +        Document doc4 = new Document();
  +        Document doc5 = new Document();
  +        doc1.add(Field.Text("body", "blueberry pie"));
  +        doc2.add(Field.Text("body", "blueberry strudel"));
  +        doc3.add(Field.Text("body", "blueberry pizza"));
  +        doc4.add(Field.Text("body", "blueberry chewing gum"));
  +        doc5.add(Field.Text("body", "piccadilly circus"));
           writer.addDocument(doc1);
           writer.addDocument(doc2);
           writer.addDocument(doc3);
           writer.addDocument(doc4);
  -	writer.optimize();
  -	writer.close();
  +        writer.addDocument(doc5);
  +        writer.optimize();
  +        writer.close();
  +
  +        IndexSearcher searcher = new IndexSearcher(indexStore);
  +
  +        PhrasePrefixQuery query1 = new PhrasePrefixQuery();
  +        PhrasePrefixQuery query2 = new PhrasePrefixQuery();
  +        query1.add(new Term("body", "blueberry"));
  +        query2.add(new Term("body", "strawberry"));
   
  -	IndexSearcher searcher = new IndexSearcher(indexStore);
  -
  -	PhrasePrefixQuery query1 = new PhrasePrefixQuery();
  -	PhrasePrefixQuery query2 = new PhrasePrefixQuery();
  -	query1.add(new Term("body", "blueberry"));
  -	query2.add(new Term("body", "strawberry"));
  -
  -	LinkedList termsWithPrefix = new LinkedList();
  +        LinkedList termsWithPrefix = new LinkedList();
           IndexReader ir = IndexReader.open(indexStore);
   
  -	// this TermEnum gives "picadelly", "pie" and "pizza".
  -        TermEnum te = ir.terms(new Term("body", "pi*"));
  +        // this TermEnum gives "piccadilly", "pie" and "pizza".
  +        String prefix = "pi";
  +        TermEnum te = ir.terms(new Term("body", prefix + "*"));
           do {
  -            termsWithPrefix.add(te.term());
  +            if (te.term().text().startsWith(prefix))
  +            {
  +                termsWithPrefix.add(te.term());
  +            }
           } while (te.next());
  -	query1.add((Term[])termsWithPrefix.toArray(new Term[0]));
  -	query2.add((Term[])termsWithPrefix.toArray(new Term[0]));
   
  -	Hits result;
  -	result = searcher.search(query1);
  -	assertEquals(2, result.length());
  +        query1.add((Term[])termsWithPrefix.toArray(new Term[0]));
  +        query2.add((Term[])termsWithPrefix.toArray(new Term[0]));
  +
  +        Hits result;
  +        result = searcher.search(query1);
  +        assertEquals(2, result.length());
   
  -	result = searcher.search(query2);
  -	assertEquals(0, result.length());
  +        result = searcher.search(query2);
  +        assertEquals(0, result.length());
       }
   }
  
  
  

---------------------------------------------------------------------
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