lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Erik Hatcher <e...@ehatchersolutions.com>
Subject Re: One direction phrase searches
Date Wed, 03 Sep 2003 00:44:54 GMT
On Tuesday, September 2, 2003, at 04:11  PM, Joe Paulsen wrote:
> It seems when I do a search such as "covered wagon" ~5 or the like,
> the systems disregards the order of my terms.  I.E., it will find 
> covered
> within 5 of wagon and it will also find wagon within 5 of covered.

I wanted to see this in action myself, so I coded up a small unit test:

     public void testOrderDoesntMatter() throws Exception {
         Directory directory = new RAMDirectory();
         IndexWriter writer = new IndexWriter(directory, new 
WhitespaceAnalyzer(), true);
         Document doc = new Document();
         doc.add(Field.Text("field", "one two"));
         writer.addDocument(doc);
         writer.optimize();
         writer.close();

         IndexSearcher searcher = new IndexSearcher(directory);
         PhraseQuery query = new PhraseQuery();
         query.setSlop(5);
         query.add(new Term("field", "two"));
         query.add(new Term("field", "one"));
         Hits hits = searcher.search(query);
         assertEquals(1, hits.length());
         searcher.close();
     }

Notice that I'm searching for "two one"~5 (yet indexed "one two") and 
it found 1 hit.



> Is there anyway to make the system respond only to the order of the
> terms as entered in the query?
>
> Joe Paulsen


Mime
View raw message