lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Chris Hostetter <hossman_luc...@fucit.org>
Subject Re: Termdocs question
Date Tue, 24 Jun 2008 23:56:41 GMT
: 
: >            termDocs = reader.termDocs(term);
: >            while(termDocs.next()){
: >                int index = termDocs.doc();
: >                if(reader.document(index).get("id").equals(id)){
: >                    reader.deleteDocument(index);
: >                }
: >            }
: 
: Iterating documents and string comparing stored values is not very efficient.
: Use a query instead, something like this:

more specificly: there is no reason at all to look at the stored value -- 
just ensure that the *indexed* value is the "unique id" (which TermDocs 
will already ensure for you)

: BooleanQuery query = new BooleanQuery();
: query.add(new TermQuery(term), Occurs.MUST);
: query.add(new TermQuery(new Term("id", id), Occurs.MUST);

note: in the orriginal code, "term" was new Term("id", id) so this is 
unneded ... the goal was to iterate the doc(s) matching a unique(?) id.



-Hoss


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