lucene-general mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ted Dunning <>
Subject Re: How to structure lucene query?
Date Sun, 07 Jun 2009 22:28:17 GMT
You can have more than one kind of document in your index.

If you have users and reports in your index then you can search users to
find those who have touched the subjects you need and then you can search
for reports authored by one of the authors qualified in the first query.
This will be pretty efficient, especially if you paginate the list of
authors so you only retrieve the documents for a few authors at a time.

To be specific, reports would have 4 fields; author_name, author_id,
report_create_dt, report_type, and
text just as you mentioned above.  I would add a globally unique report id
called report_id.

Then authors would have a few fields: user_id, user_name,
report_types_written and report_ids_written.

Query one would be

*report_types_written:(+"XYZ" +"ABC")

And you would retain user_name, report_ids_written.  Note that reports don't
have this field and thus will never be retrieved here.

Suppose you find the following three authors:

*user_id: 52, user_name: Alice, report_ids_written: 1, 3, 5, 7*
*user_id: 1327, user_name: Bob, report_ids_written: 22, 11, 55, 77, 3*
*user_id: 52, user_name: Alice, report_ids_written: 4, 6, 12*

The second query would be

*report_id:(1 3 4 5 6 7 11 12 22 55 77) *

If you find thousands of reports that you want to retrieve, you should
retrieve them in batches.  If you present the authors in pages of 10 or 20,
then you are unlikely to have more than dozens of reports to retrieve per

Note that the second query will only retrieve reports because authors don't
have that field.

If you want to limit the dates for the second query, you could use this:

*+report_id:(1 3 4 5 6 7 11 12 22 55 77) **+report_create_dt:[20051009 TO

Note how there is now a + on the first term.  It could have been used on the
first version of the second query but would have had no effect.  Once you
add additional terms, however, you need to include the plusses to make sure
you strictly apply all the conditions you need.


On Sun, Jun 7, 2009 at 11:48 AM, ywlee522 <> wrote:

> The query is "of the users who has one or more reports containing "ABC",
> find users who also has one or more reports containing "XYZ".
> ..
> If I put all reports of a user into a single Lucene document, then it is
> equal to find all documents containing  both "ABC" and "XYZ".  But, then, i
> will lose the report_dt field, which is another parameter in the query.

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