Sunday, December 11, 2022

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

Issue

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


Solution

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



Answered By - Eser Aygün
Answer Checked By - Candace Johnson (PHPFixing Volunteer)

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.