Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to write a solr query for retrieving all records with numeric field value less then specified?

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)"

like image 810
Roman Avatar asked Dec 30 '11 11:12

Roman


People also ask

How query all fields in Solr?

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.

How do you write a query in Solr?

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.

How do I query in Solr collection?

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.


2 Answers

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

like image 91
Eser Aygün Avatar answered Oct 21 '22 13:10

Eser Aygün


also note that performancewise you should use a filter query for this:

&q=name:ipod&fq=price:[* TO 100]
like image 14
Bob Yoplait Avatar answered Oct 21 '22 12:10

Bob Yoplait