You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@lucene.apache.org by ro...@xemaps.com on 2010/05/13 01:42:33 UTC
TermDocs
Hi guys,
I've had this code for some time but am just now questioning if it works.
I have a custom filter that i've been using since Lucene 1.4 to Lucene 2.2.0 and it essentially builds up a BitSet like so:
for ( int x = 0; x < fields.length; x++ ) {
for ( int y = 0; y < values.length; y++ ) {
TermDocs termDocs = reader.termDocs( new Term( fields[x], values[y] ) );
try {
while ( termDocs.next() ) {
int doc = termDocs.doc();
bits.set( doc );
}
}
finally {
termDocs.close();
}
}
}
I notice that it grabs all the TermDocs for the first field and value but nothing after that. But I do know that the other values exist but I don't get any TermDocs afterwards.
Do I need to reopen the IndexReader each time?
Regards,
Roy
---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org
Re: TermDocs
Posted by Grant Ingersoll <gs...@apache.org>.
On May 12, 2010, at 7:42 PM, roy-lucene-user@xemaps.com wrote:
> Hi guys,
>
> I've had this code for some time but am just now questioning if it works.
>
> I have a custom filter that i've been using since Lucene 1.4 to Lucene 2.2.0 and it essentially builds up a BitSet like so:
>
> for ( int x = 0; x < fields.length; x++ ) {
> for ( int y = 0; y < values.length; y++ ) {
> TermDocs termDocs = reader.termDocs( new Term( fields[x], values[y] ) );
> try {
> while ( termDocs.next() ) {
> int doc = termDocs.doc();
> bits.set( doc );
> }
> }
> finally {
> termDocs.close();
> }
> }
> }
>
> I notice that it grabs all the TermDocs for the first field and value but nothing after that. But I do know that the other values exist but I don't get any TermDocs afterwards.
>
That code works for me against Lucene 3.0.1 (and I don't think much has changed there). Are you sure the fields and values are lining up right? Perhaps isolate this on a standalone index to convince yourself. Have you looked at Luke to validate?
However, why not just create a Filter from a Query and get the bitset/docidset using the MultiFieldQueryParser?
//Here's a snippet I wrote, never mind the PayloadAnalyzer, just substitute in your analyzer
MultiFieldQueryParser mfqp = new MultiFieldQueryParser(Version.LUCENE_30, fields, new PayloadAnalyzer(encoder));
Query query = mfqp.parse(Version.LUCENE_30, values, fields, new PayloadAnalyzer(encoder));
Filter filter = new QueryWrapperFilter(query);
DocIdSet docs = filter.getDocIdSet(reader);
DocIdSetIterator docIdSetIterator = docs.iterator();
while (docIdSetIterator.nextDoc() != DocIdSetIterator.NO_MORE_DOCS){
System.out.println("Doc: " + docIdSetIterator.docID());
}
--------------------------
Grant Ingersoll
http://www.lucidimagination.com/
Search the Lucene ecosystem using Solr/Lucene: http://www.lucidimagination.com/search
---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org