lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Erick Erickson" <erickerick...@gmail.com>
Subject Re: search by field, not field value
Date Sun, 12 Nov 2006 18:03:55 GMT
I'm going mostly from memory here, so the details may not be entirely
accurate, but.....

See TermDocs (FilterTermDocs?). Use the seek method to get to the term e.g.

TermDocs.seek(new Term("specific_field", ""));

 Note that the "" as the value of the term gets all the terms. Then use
TermDocs.next until it returns false. At each point, TermDocs.doc() will
give you the Lucene ID of a document containing that term.

Really, this enumerates all the documents that have any values in
specific_field.

One issue here is that you'll get multiple hits per document. For instance,
say you've indexed A, B, and C as values in specific_field for document 5.
Just blindly doing the next() call will get you document 5 three times. You
can use TermDocs.skipTo(current document + 1). to insure that you only
process a document once. This is either a minor efficiency or a major time
savings, depending on the characteristics of your index..... Be a bit
careful and only call next() if you *don't* use skipto, or you may skip a
doc that only has one value for specific_field.

Hope this helps
Erick




On 11/12/06, Simon Willnauer <simon.willnauer@googlemail.com> wrote:
>
> Hey tony,
> I guess the easiest way for you to do that is to create a extra field
> containig the field names and just fire a boolean query on this extra
> field.
>
> best regards simon
>
> On 11/12/06, tony yin <gaoligong@gmail.com> wrote:
> > I want search document by specific field, not by field value, How to?
> >
> > I have some document store in fields{content, key, path} and some in
> > {content, key, path, specific_field}
> >
> > and I want to find all the document that have specific_field, Could you
> help
> > me?
> >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
> For additional commands, e-mail: java-user-help@lucene.apache.org
>
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message