lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Paul Taylor <paul_t...@fastmail.fm>
Subject Re: Why is the old value still in the index
Date Fri, 16 Dec 2011 17:19:45 GMT
On 16/12/2011 17:10, Ian Lea wrote:
> Shouldn't
>
> iw.updateDocument(new Term(FIELD1,"term1"),document);
>
> be
>
> iw.updateDocument(new Term(FIELD1,"test"),document);
>
> if you want to replace the first doc?
Hmm, you are right if I change it I then get

TermDocsFreq1
test
TermDocsFreq1
test2



(but doesn't resolve the program with my real code that doesnt seem to 
have this mistake :()

What I dont understand then is in the incorrect example why don't I get

TermDocsFreq2


if Ive actually create another document rather than updating one ?

-- Ian. On Fri, Dec 16, 2011 at 4:54 PM, Paul Taylor 
<paul_t100@fastmail.fm> wrote:
>> I'm adding documents to an index, at a later date I modify a document and
>> update the index, close the writer and open a new IndexReader. My
>> indexreader iterates over terms for that field and docFreq() returns one as
>> I would expect, however the iterator  returns both the old value of the
>> document and the new value, I don't expect (or want) the old value to still
>> be in the index, so why is this.
>>
>>
>> This full test program generates:
>>
>> TermDocsFreq1
>> test
>> TermDocsFreq1
>> test
>> test2
>>
>> Dont expect to see 'test' listed the second time
>>
>>
>> package com.jthink.jaikoz;
>>
>> import org.apache.lucene.analysis.standard.StandardAnalyzer;
>> import org.apache.lucene.document.Document;
>> import org.apache.lucene.document.Field;
>> import org.apache.lucene.index.*;
>> import org.apache.lucene.store.RAMDirectory;
>> import org.apache.lucene.util.Version;
>>
>>
>> public class LuceneTest
>> {
>>     public  static void main(String []args)
>>     {
>>         try
>>         {
>>             String FIELD1="field1";
>>             RAMDirectory dir = new RAMDirectory();
>>             IndexWriterConfig iwc = new IndexWriterConfig(Version.LUCENE_35,
>> new StandardAnalyzer(Version.LUCENE_35));
>>             IndexWriter       iw  = new IndexWriter(dir, iwc);
>>             Document document = new Document();
>>             document.add(new Field(FIELD1,"test", Field.Store.YES,
>> Field.Index.ANALYZED));
>>             iw.addDocument(document);
>>             iw.close();
>>
>>             IndexReader ir = IndexReader.open(dir,true);
>>             TermEnum terms = ir.terms(new Term(FIELD1));
>>             System.out.println("TermDocsFreq"+terms.docFreq());
>>             do
>>             {
>>                 if (terms.term() != null)
>>                 {
>>                     System.out.println(terms.term().text());
>>                 }
>>             }
>>             while (terms.next()&&  terms.term().field().equals(FIELD1));
>>
>>             IndexWriterConfig iwc2 = new IndexWriterConfig(Version.LUCENE_35,
>> new StandardAnalyzer(Version.LUCENE_35));
>>             iw  = new IndexWriter(dir, iwc2);
>>             document = new Document();
>>             document.add(new Field(FIELD1,"test2", Field.Store.YES,
>> Field.Index.ANALYZED));
>>             iw.updateDocument(new Term(FIELD1,"term1"),document);
>>             iw.close();
>>
>>             ir = IndexReader.open(dir,true);
>>             terms = ir.terms(new Term(FIELD1));
>>             System.out.println("TermDocsFreq"+terms.docFreq());
>>             do
>>             {
>>                 if (terms.term() != null)
>>                 {
>>                     System.out.println(terms.term().text());
>>                 }
>>             }
>>             while (terms.next()&&  terms.term().field().equals(FIELD1));
>>         }
>>         catch(Exception ex)
>>         {
>>             ex.printStackTrace();
>>         }
>>     }
>>
>> }
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
>> For additional commands, e-mail: java-user-help@lucene.apache.org
>>


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