lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Karl Wettin <karl.wet...@gmail.com>
Subject Re: instantiated index in 2.4
Date Mon, 15 Sep 2008 20:06:27 GMT

15 sep 2008 kl. 18.51 skrev Karl Wettin:
>
>> Are the adds reflected directly to the index?
>
> Yes. An InstantiatedIndexReader is always current.
> You will probably still have to reconstruct your searcher.
> I never really looked in to what happends if you don't.

The second statement was wrong. There is no need to reconstruct the  
searcher, new documents are immediatly available as search results  
after a commit:

public class TestSearch extends TestCase {

   public void test() throws Exception {

     InstantiatedIndex index = new InstantiatedIndex();
     InstantiatedIndexReader reader = new  
InstantiatedIndexReader(index);
     IndexSearcher searcher = new IndexSearcher(reader);
     InstantiatedIndexWriter writer = new  
InstantiatedIndexWriter(index);

     Document doc;
     Collector collector;

     doc = new Document();
     doc.add(new Field("f", "a", Field.Store.NO,  
Field.Index.NOT_ANALYZED));
     writer.addDocument(doc);
     writer.commit();

     collector = new Collector();
     searcher.search(new TermQuery(new Term("f", "a")), collector);
     assertEquals(1, collector.hits);

     doc = new Document();
     doc.add(new Field("f", "a", Field.Store.NO,  
Field.Index.NOT_ANALYZED));
     writer.addDocument(doc);
     writer.commit();

     collector = new Collector();
     searcher.search(new TermQuery(new Term("f", "a")), collector);
     assertEquals(2, collector.hits);

   }

   public static class Collector extends HitCollector {
     private int hits = 0;
     public void collect(int doc, float score) {
       hits++;
     }
   }



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


Mime
View raw message