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 "Killeen, Tom" <to...@thomson.com> on 2003/09/17 16:00:53 UTC

slow performance with Date Range Searching

Hello all, 

I have recently indexed approx 15.8 million XML documents in which I index
the contents certain elements (titles, states, dates to name a few).  I have
27 separate indices and use a MultiSearcher to search these indices.  

When I search on the title and state fields with multiple terms searching is
very fast.  For example I get a hit count of 227, 000 in .4 seconds.  But
when I throw a date range in the search, performance suffers significantly.


My query would look something like this: LongTitle:killeen AND
LongTitle:state AND StateDistrict:id AND FiledDate:["1997-01-01" TO
"2002-04-04"] and it returned in 
5.7 seconds


Does anyone have any suggestions for searching date ranges.  Our ranges will
generally be between a 3 - 7 year period.

thanks, 
Tom

Re: slow performance with Date Range Searching

Posted by Eric Jain <Er...@isb-sib.ch>.
> Does anyone have any suggestions for searching date ranges.  Our
> ranges will generally be between a 3 - 7 year period.

Apparently Lucene expands ranges to boolean 'or' queries. So if you have
a thousand distinct dates within a range, Lucene will build a query with
a thousand terms...

One workaround is to first run the query, but without ranges. Store the
results into a bit vector with the position corresponding to the
document id. Then create a TermEnum that starts with the lower range
value. For each term, get the document ids, and set the corresponding
values in a second bit vector. Break the loop as soon as the TermEnum
has reached or passed the upper limit of the range. Finally, 'and' or
'or' the second bit vector with the first one. It's as simple as that
:-)

I wonder why Lucene doesn't use this strategy by default. I realize it
is less efficient when the range includes few terms, but it seems to
scale far better.

--
Eric Jain


---------------------------------------------------------------------
To unsubscribe, e-mail: lucene-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: lucene-user-help@jakarta.apache.org


Re: slow performance with Date Range Searching

Posted by Eric Jain <Er...@isb-sib.ch>.
> Does anyone have any suggestions for searching date ranges.  Our
> ranges will generally be between a 3 - 7 year period.

Apparently Lucene expands ranges to boolean 'or' queries. So if you have
a thousand distinct dates within a range, Lucene will build a query with
a thousand terms...

One workaround is to first run the query, but without ranges. Store the
results into a bit vector with the position corresponding to the
document id. Then create a TermEnum that starts with the lower range
value. For each term, get the document ids, and set the corresponding
values in a second bit vector. Break the loop as soon as the TermEnum
has reached or passed the upper limit of the range. Finally, 'and' or
'or' the second bit vector with the first one. It's as simple as that
:-)

I wonder why Lucene doesn't use this strategy by default. I realize it
is less efficient when the range includes few terms, but it seems to
scale far better.

--
Eric Jain


Re: slow performance with Date Range Searching

Posted by Erik Hatcher <er...@ehatchersolutions.com>.
And with the latest Lucene codebase in CVS, you could also use a 
DateFilter wrapped inside a CachingWrapperFilter instead of a 
QueryFilter.  Just wanted to mention what is now available.

But I'll reiterate what Doug says... be sure to save off the filter 
instance so you don't take the filtering performance hit for the same 
date ranges on later searches.

	Erik


On Wednesday, September 17, 2003, at 11:57  AM, Doug Cutting wrote:

> Killeen, Tom wrote:
>> My query would look something like this: LongTitle:killeen AND
>> LongTitle:state AND StateDistrict:id AND FiledDate:["1997-01-01" TO
>> "2002-04-04"] and it returned in 5.7 seconds
>> Does anyone have any suggestions for searching date ranges.  Our 
>> ranges will
>> generally be between a 3 - 7 year period.
>
> If you use the same date range repeatedly then you can make things 
> fast by replacing it with a filter that you re-use.  Try using a 
> QueryFilter with your date range query as the query.  Save the 
> QueryFilter object and use it again with future queries.  The first 
> query will be slow, but subsequent queries will use the cached results 
> of the first.
>
> This is the recommended way to implement a "within the last month", 
> "within the last year", etc. feature.  You could even pre-fetch the 
> filter whenever you update the index, by evaluating a query before you 
> put a new IndexReader in production, so that even the first real user 
> query is fast.
>
> Doug
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: lucene-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: lucene-user-help@jakarta.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: lucene-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: lucene-user-help@jakarta.apache.org


Re: slow performance with Date Range Searching

Posted by Erik Hatcher <er...@ehatchersolutions.com>.
And with the latest Lucene codebase in CVS, you could also use a 
DateFilter wrapped inside a CachingWrapperFilter instead of a 
QueryFilter.  Just wanted to mention what is now available.

But I'll reiterate what Doug says... be sure to save off the filter 
instance so you don't take the filtering performance hit for the same 
date ranges on later searches.

	Erik


On Wednesday, September 17, 2003, at 11:57  AM, Doug Cutting wrote:

> Killeen, Tom wrote:
>> My query would look something like this: LongTitle:killeen AND
>> LongTitle:state AND StateDistrict:id AND FiledDate:["1997-01-01" TO
>> "2002-04-04"] and it returned in 5.7 seconds
>> Does anyone have any suggestions for searching date ranges.  Our 
>> ranges will
>> generally be between a 3 - 7 year period.
>
> If you use the same date range repeatedly then you can make things 
> fast by replacing it with a filter that you re-use.  Try using a 
> QueryFilter with your date range query as the query.  Save the 
> QueryFilter object and use it again with future queries.  The first 
> query will be slow, but subsequent queries will use the cached results 
> of the first.
>
> This is the recommended way to implement a "within the last month", 
> "within the last year", etc. feature.  You could even pre-fetch the 
> filter whenever you update the index, by evaluating a query before you 
> put a new IndexReader in production, so that even the first real user 
> query is fast.
>
> Doug
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: lucene-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: lucene-user-help@jakarta.apache.org


Re: slow performance with Date Range Searching

Posted by Doug Cutting <cu...@lucene.com>.
Killeen, Tom wrote:
> My query would look something like this: LongTitle:killeen AND
> LongTitle:state AND StateDistrict:id AND FiledDate:["1997-01-01" TO
> "2002-04-04"] and it returned in 
> 5.7 seconds
> 
> Does anyone have any suggestions for searching date ranges.  Our ranges will
> generally be between a 3 - 7 year period.

If you use the same date range repeatedly then you can make things fast 
by replacing it with a filter that you re-use.  Try using a QueryFilter 
with your date range query as the query.  Save the QueryFilter object 
and use it again with future queries.  The first query will be slow, but 
subsequent queries will use the cached results of the first.

This is the recommended way to implement a "within the last month", 
"within the last year", etc. feature.  You could even pre-fetch the 
filter whenever you update the index, by evaluating a query before you 
put a new IndexReader in production, so that even the first real user 
query is fast.

Doug


Re: slow performance with Date Range Searching

Posted by Doug Cutting <cu...@lucene.com>.
Killeen, Tom wrote:
> My query would look something like this: LongTitle:killeen AND
> LongTitle:state AND StateDistrict:id AND FiledDate:["1997-01-01" TO
> "2002-04-04"] and it returned in 
> 5.7 seconds
> 
> Does anyone have any suggestions for searching date ranges.  Our ranges will
> generally be between a 3 - 7 year period.

If you use the same date range repeatedly then you can make things fast 
by replacing it with a filter that you re-use.  Try using a QueryFilter 
with your date range query as the query.  Save the QueryFilter object 
and use it again with future queries.  The first query will be slow, but 
subsequent queries will use the cached results of the first.

This is the recommended way to implement a "within the last month", 
"within the last year", etc. feature.  You could even pre-fetch the 
filter whenever you update the index, by evaluating a query before you 
put a new IndexReader in production, so that even the first real user 
query is fast.

Doug


---------------------------------------------------------------------
To unsubscribe, e-mail: lucene-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: lucene-user-help@jakarta.apache.org