Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

choose solr documents where one field is great than another

Tags:

solr

What is the syntax for choosing solr documents where one field is great than another?

More specifically, this is for two fields that contains dates.

like image 204
Joyce Avatar asked Mar 27 '12 15:03

Joyce


People also ask

How do I search a specific field in SOLR?

If you do not specify a field in a query, Solr searches only the default field. Alternatively, you can specify a different field or a combination of fields in a query. To specify a field, type the field name followed by a colon ":" and then the term you are searching for within the field.

What is the difference between Q and FQ in SOLR?

Standard solr queries use the "q" parameter in a request. Filter queries use the "fq" parameter. The primary difference is that filtered queries do not affect relevance scores; the query functions purely as a filter (docset intersection, essentially).

What is filter query in SOLR?

Solr provides Query (q parameter) and Filter Query (fq parameter) for searching. The query (q parameter), as the name suggests, is the main query used for searching. Example. q = title:james. Filter queries are used alongside query (q parameter) to limit results of queries using additional filters.


1 Answers

I found this question looking for the same thing. As it turns out, you can filter by field comparisons using a filter query, particularly frange and sub.

frange can take a lower bound l or an upper bound u, or both. Optional values incl and incu inform the filter if the boundaries are inclusive or not.

sub subtracts the literal numbers or document fields.

So the answer is to add a filter that accepts only those documents where A minus B is greater than zero. Set the lower bound to 0, omit the upper bound, and set incl to false to exclude the lower bound itself (to remove documents where A==B)

fq={!frange l=0 incl=false}sub(A,B)

URL Encoded: fq=%7B!frange+l%3D0+incl%3Dfalse%7Dsub(A%2CB)

like image 147
bibby Avatar answered Oct 12 '22 22:10

bibby