[ 
https://issues.apache.org/jira/browse/LUCENE-6661?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14616316#comment-14616316
 ] 

Adrien Grand commented on LUCENE-6661:
--------------------------------------

bq. I think you mean "rewritten" not "reused" in that sentence

It is true that the query cache only caches on the rewritten query, but what I 
meant is that we try to only cache queries if there is evidence of reuse. Let 
me try to clarify:

The query cache is split in two parts: the actual cache (oal.search.QueryCache) 
which maps (Query, segment) pairs to cached DocIdSets, and a caching policy 
(oal.search.QueryCachingPolicy) which defines whether to cache a query or not. 
In the above example, I was assuming that that the caching policy would only 
cache queries if there is evidence of reuse. For instance, we have 
oal.search.UsageTrackingQueryCachingPolicy which keeps a ring buffer of the 
hashcodes of the 256 most-recently used queries, and only decides to cache a 
query if its hashcode appears 5 times or more in this ring buffer.

The reasoning behind only caching if there is evidence of reuse is that caching 
is wasteful if the cache entry is never reused given that it needs to read the 
whole set of matching documents, while intersecting two queries together often 
skips over large portions of the doc ID space.

The query which is used for caching is the one returned by Weight.getQuery(). 
This helps since all queries that are rewritten to the same query will share 
the same cache key, but it also means that if you provide a new unique query in 
every call to Query.createWeight then the query will never be cached.

> Allow queries to opt out of caching
> -----------------------------------
>
>                 Key: LUCENE-6661
>                 URL: https://issues.apache.org/jira/browse/LUCENE-6661
>             Project: Lucene - Core
>          Issue Type: Improvement
>    Affects Versions: 5.2
>            Reporter: Terry Smith
>            Priority: Minor
>         Attachments: LUCENE-6661.patch
>
>
> Some queries have out-of-band dependencies that make them incompatible with 
> caching, it'd be great if they could opt out of the new fancy query/filter 
> cache in IndexSearcher.
> This affects DrillSidewaysQuery and any user-provided custom Query 
> implementations.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to