You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@solr.apache.org by Wei <we...@gmail.com> on 2023/05/25 17:00:06 UTC

Question on Solr filter syntax

  Send on behalf of my colleague as his email seems not showing up in the
list.

Hi Team,


I was reading about special filter syntax in Solr documentation -

https://solr.apache.org/guide/8_3/the-standard-query-parser.html#differences-between-lucenes-classic-query-parser-and-solrs-standard-query-parser


Support for a special filter(…) syntax to indicate that some query
clauses should be cached in the filter cache (as a constant score
boolean query). This allows sub-queries to be cached and re-used in
other queries. For example inStock:true will be cached and re-used in
all three of the queries below:

q=features:songs OR filter(inStock:true)


My question is how do I disable cache for part of OR filter query and
enable for part of OR filter query?


For e.g. - Current FQ -

fq: planName:all_features OR zipCode:1234 (in this case entire FQ is cached)


I don't want to cache the entire FQ given it's very unique , but I
want to cache the first part (plan_name:all_features) to improve
performance . How do I achieve this?


My understanding is the following should work? Is this correct?

fq: {!cache=false}(filter(planName:all_features) OR zipCode:1234)


Will the above syntax result in planName:all_features to be cached in
Filter Cache? Otherwise how can I achieve this?


I am on Solr 8.4


Thanks,

Yash

Re: Question on Solr filter syntax

Posted by Shawn Heisey <ap...@elyograg.org>.
On 5/25/23 11:00, Wei wrote:
> For e.g. - Current FQ -
> 
> fq: planName:all_features OR zipCode:1234 (in this case entire FQ is cached)
> 
> I don't want to cache the entire FQ given it's very unique , but I
> want to cache the first part (plan_name:all_features) to improve
> performance . How do I achieve this?

I am about 90 percent sure this is not possible.  In the filterCache, 
the entire text of the filter is used as the key for each entry in the 
cache.

I'm not familiar with that part of the code, but I bet that even if it 
IS possible, and it might not be, it would take a near-complete rewrite 
of Solr's filter query code.

Thanks,
Shawn

Re: Question on Solr filter syntax

Posted by Chris Hostetter <ho...@fucit.org>.
: For e.g. - Current FQ -
: fq: planName:all_features OR zipCode:1234 (in this case entire FQ is cached)
: 
: I don't want to cache the entire FQ given it's very unique , but I
: want to cache the first part (plan_name:all_features) to improve
: performance . How do I achieve this?
: 
: 
: My understanding is the following should work? Is this correct?
: 
: fq: {!cache=false}(filter(planName:all_features) OR zipCode:1234)

Correct.

In small scale testing you can see it work by looking at your cache 
metrics -- I've included a `bin/solr -e techproducts` example below my 
sig...


-Hoss
http://www.lucidworks.com/




hossman@slate:~$ curl -sS 'http://localhost:8983/solr/admin/metrics?omitHeader=true&key=solr.core.techproducts:CACHE.searcher.filterCache'
{
  "metrics":{
    "solr.core.techproducts:CACHE.searcher.filterCache":{
      "lookups":0,
      "hits":0,
      "hitratio":1.0,
      "inserts":0,
      "evictions":0,
      "size":0,
      "warmupTime":0,
      "ramBytesUsed":448,
      "maxRamMB":-1,
      "cumulative_lookups":0,
      "cumulative_hits":0,
      "cumulative_hitratio":1.0,
      "cumulative_inserts":0,
      "cumulative_evictions":0}}}
hossman@slate:~$ curl --globoff -sS 'http://localhost:8983/solr/techproducts/select?q=*:*&rows=0&omitHeader=true&fq={!cache=false}(filter(inStock:true)+OR+id:IW-02)'
{
  "response":{"numFound":18,"start":0,"numFoundExact":true,"docs":[]
  }}
hossman@slate:~$ curl -sS 'http://localhost:8983/solr/admin/metrics?omitHeader=true&key=solr.core.techproducts:CACHE.searcher.filterCache'
{
  "metrics":{
    "solr.core.techproducts:CACHE.searcher.filterCache":{
      "lookups":1,
      "hits":0,
      "hitratio":0.0,
      "inserts":1,
      "evictions":0,
      "size":1,
      "warmupTime":0,
      "ramBytesUsed":1744,
      "maxRamMB":-1,
      "cumulative_lookups":1,
      "cumulative_hits":0,
      "cumulative_hitratio":0.0,
      "cumulative_inserts":1,
      "cumulative_evictions":0}}}
hossman@slate:~$ curl --globoff -sS 'http://localhost:8983/solr/techproducts/select?q=*:*&rows=0&omitHeader=true&fq={!cache=false}(filter(inStock:true)+OR+id:GB18030TEST)'
{
  "response":{"numFound":17,"start":0,"numFoundExact":true,"docs":[]
  }}
hossman@slate:~$ curl -sS 'http://localhost:8983/solr/admin/metrics?omitHeader=true&key=solr.core.techproducts:CACHE.searcher.filterCache'
{
  "metrics":{
    "solr.core.techproducts:CACHE.searcher.filterCache":{
      "lookups":2,
      "hits":1,
      "hitratio":0.5,
      "inserts":1,
      "evictions":0,
      "size":1,
      "warmupTime":0,
      "ramBytesUsed":1744,
      "maxRamMB":-1,
      "cumulative_lookups":2,
      "cumulative_hits":1,
      "cumulative_hitratio":0.5,
      "cumulative_inserts":1,
      "cumulative_evictions":0}}}