Let's assume we have a set of mp3-players with names and prices.
How to write a correct solr query for finding all goods with a certain name and with price less then 100$?
q = "(name:(ipod) AND price ???? 100.0)"
The correct way is the copyField you have and declaring the field all as the default search field. That's how the examples that ship with Solr out of the box do it. Excellent, adding <str name="df">all</str> to defaults in solrconfig. xml indeed solved this.
Trying a basic queryThe main query for a solr search is specified via the q parameter. Standard Solr query syntax is the default (registered as the “lucene” query parser). If this is new to you, please check out the Solr Tutorial. Adding debug=query to your request will allow you to see how Solr is parsing your query.
You can search for "solr" by loading the Admin UI Query tab, enter "solr" in the q param (replacing *:* , which matches all documents), and "Execute Query". See the Searching section below for more information. To index your own data, re-run the directory indexing command pointed to your own directory of documents.
I don't think the query parser supports <
operator. You have to define a RangeQuery explicitly. You can then attach a name query to that using a BooleanQuery.
Update: Apparently, I was wrong. In fact, Solr's query parser is smarter than Lucene's. Here is your answer: https://lucene.apache.org/solr/guide/8_0/the-standard-query-parser.html#differences-between-lucene-s-classic-query-parser-and-solr-s-standard-query-parser
field:[* TO 100] finds all field values less than or equal to 100
also note that performancewise you should use a filter query for this:
&q=name:ipod&fq=price:[* TO 100]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With