Time for action – using q.op for the default Boolean operator

The q.op parameter gives us the opportunity to choose what kind of boolean operator should be used in the query. It is generally preferable to choose an OR behavior, because it is more intuitive to reflect user expectations, and AND will act as a filter:

  1. We can use the default value for q.op in an explicit way.
    >> curl -G 'http://localhost:8983/solr/paintings/select?rows=0&wt=json' --data-urlencode 'q={!lucene q.op=OR}dali christ'
    

    The command gives the following output:

    {"responseHeader":{"status":0,"QTime":5},"response" {"numFound":155,"start":0,"docs":[]}}
    
  2. We can even override the default choice, adopting a behavior based on AND operator instead.
    >> curl -G 'http://localhost:8983/solr/paintings/select?rows=0&wt=json' --data-urlencode 'q={!lucene q.op=AND}dali christ'
    

    The output obtained is as follows:

    {"responseHeader":{"status":0,"QTime":5},"response":{"numFound":4,"start":0,"docs":[]}}
    

As expected, it returns less results. Notice that in this case we deliberately omit the documents returned with value of rows as 0.

What just happened?

In these examples, we saw how simple it is to use different values for the q.op parameter. Since these parameters control the default way in which a collection of terms are combined for a search, this should be used carefully. Also, you should not expect it to change its default value unless you have a very particular case. For example, if we had a request for using restrictive search keywords since the AND operator allows the addition of a filter for every term.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.135.196.103