Information Retrieval,  Python,  Solr

Apache Solr 7.5 The Standard Query Parser focus searching

http://lucene.apache.org/solr/guide/7_5/the-standard-query-parser.html

Solr’s default Query Parser is also known as the “lucene” parser.

The key advantage of the standard query parser is that it supports a robust and fairly intuitive syntax allowing you to create a variety of structured queries. The largest disadvantage is that it’s very intolerant of syntax errors, as compared with something like the DisMax query parser which is designed to throw as few errors as possible.

Standard Query Parser Parameters

In addition to the Common Query Parameters, Faceting Parameters, Highlighting Parameters, and MoreLikeThis Parameters, the standard query parser supports the parameters described in the table below.

  • q: Defines a query using standard query syntax. This parameter is mandatory.
  • q.op: Specifies the default operator for query expressions, overriding the default operator specified in the Schema. Possible values are “AND” or “OR”.
  • df: Specifies a default field, overriding the definition of a default field in the Schema.
  • sow: Split on whitespace. If set to true, text analysis is invoked separately for each individual whitespace-separated term. The default is false; whitespace-separated term sequences will be provided to text analysis in one shot, enabling proper function of analysis filters that operate over term sequences, e.g., multi-word synonyms and shingles.

Default parameter values are specified in solrconfig.xml, or overridden by query-time values in the request.

We are going to focus on the q parameter for searching.

The code is at https://github.com/spawnmarvel/solrhttp

So I have changed the test-data a bit, format now is:

9991;Item-9991;Fuel Area 9991;System 4
9992;Item-9992;Monitor Housing 9992;System 4
9993;Item-9993;Fuel Gate 9993;System 4
9994;Item-9994;Heat Area 9994;System 4
9995;Item-9995;Valve Ice 9995;System 4
9996;Item-9996;Oil Water 9996;System 4
9997;Item-9997;Door High 9997;System 4
9998;Item-9998;TurbinEngine Low 9998;System 4
9999;Item-9999;Fuel Area 9999;System 4

And we have 10000 items stored in Solr (ref generate_test_data()).

Search using run_search.py

Get item where id = 1:

http://localhost:8983/solr/newcore/select?q=id:1

Get items in range 9980-9982:

http://localhost:8983/solr/newcore/select?q=id:[9980 TO 9982]

Get item with desc like Gas and return max 7 rows:
http://localhost:8983/solr/newcore/select?q=desc:*Gas*&rows=7
Solr Wiki:

 

Experiment with the Querybuilder in Solr and you will learn and also get the url ready for your application:

Happy index and happy searching.

 

 

 

Comments Off on Apache Solr 7.5 The Standard Query Parser focus searching