You are viewing a plain text version of this content. The canonical link for it is here.
Posted to solr-user@lucene.apache.org by Mikhail Ibraheem <mi...@yahoo.com.INVALID> on 2017/06/01 17:46:23 UTC

Solr query with more than one field

Hi,I have 2 fields "cost" and "value" at my records. I want to get all documents that have "value" greater than "cost". Something likeq=value:[cost TO *]
Please advise.
Thanks

Re: Solr query with more than one field

Posted by Chris Hostetter <ho...@fucit.org>.
: I could have sworn I was paraphrasing _your_ presentation Hoss. I
: guess I did not learn my lesson well enough.
: 
: Thank you for the correction.

Trust but verify! ... we're both wrong.

Boolean functions (like lt(), gt(), etc...) behave just like sum() -- they 
"exist" for a  document if and only if all the args exist for the document 
-- and that's what matters for wether a '{!func}' query considers a 
document a match. (if the function "exists" then the query "matches")

I think my second suggestion of using frange is the only thing that works 
-- you have to explicitly use 'frange' which will only match a document if 
the function "exists" *AND* if the resulting value is in the range...

	fq={!frange l=0}sub(value,cost)

what would be nice is the inverse of the "exists()" function ... that 
returns true/false depending on wether the function it wraps "exists" for 
a document -- but is always a "match" for every doc.  we need *something* 
that can wrap a function that returns a boolean and only "exists" if the 
boolean is true, otherwise it's considered a non-exists/match for the doc.

then you could do:  fq={!func}something(gt(value,cost))

of perhaps just a nomatch()/noexist() function that takes no args and does 
nothing but never exists/matches any doc .... then you could do...

    fq={!func}if(gt(value,cost),42,nomatch())

?

-Hoss
http://www.lucidworks.com/

Re: Solr query with more than one field

Posted by Alexandre Rafalovitch <ar...@gmail.com>.
Bother,

I could have sworn I was paraphrasing _your_ presentation Hoss. I
guess I did not learn my lesson well enough.

Thank you for the correction.

Regards,
   Alex.
----
http://www.solr-start.com/ - Resources for Solr users, new and experienced


On 1 June 2017 at 15:26, Chris Hostetter <ho...@fucit.org> wrote:
>
> : Because the value of the function will be treated as a relevance value
> : and relevance value of 0 (and less?) will cause the record to be
> : filtered out.
>
> I don't believe that's true? ... IIRC 'fq' doesn't care what the scores
> are as long as the query is a "match" and a 'func' query will match as
> long as the function says it matches ... something like sub() should be a
> match as long sa both fields exist in the document.
>
> Pretty sure the simplest version of what you want is
> 'fq={!func}gt(value,cost)' .. of if you need more complex functions/rules
> you can use the 'frange' QParser to only match documents where the result
> of an equation is in a specific range of values...
>
> https://cwiki.apache.org/confluence/display/solr/Other+Parsers#OtherParsers-FunctionRangeQueryParser
>
> : On 1 June 2017 at 13:46, Mikhail Ibraheem
> : <mi...@yahoo.com.invalid> wrote:
> : > Hi,I have 2 fields "cost" and "value" at my records. I want to get all documents that have "value" greater than "cost". Something likeq=value:[cost TO *]
> : > Please advise.
> : > Thanks
> :
>
> -Hoss
> http://www.lucidworks.com/

Re: Solr query with more than one field

Posted by Chris Hostetter <ho...@fucit.org>.
: Because the value of the function will be treated as a relevance value
: and relevance value of 0 (and less?) will cause the record to be
: filtered out.

I don't believe that's true? ... IIRC 'fq' doesn't care what the scores 
are as long as the query is a "match" and a 'func' query will match as 
long as the function says it matches ... something like sub() should be a 
match as long sa both fields exist in the document.

Pretty sure the simplest version of what you want is 
'fq={!func}gt(value,cost)' .. of if you need more complex functions/rules 
you can use the 'frange' QParser to only match documents where the result 
of an equation is in a specific range of values...

https://cwiki.apache.org/confluence/display/solr/Other+Parsers#OtherParsers-FunctionRangeQueryParser

: On 1 June 2017 at 13:46, Mikhail Ibraheem
: <mi...@yahoo.com.invalid> wrote:
: > Hi,I have 2 fields "cost" and "value" at my records. I want to get all documents that have "value" greater than "cost". Something likeq=value:[cost TO *]
: > Please advise.
: > Thanks
: 

-Hoss
http://www.lucidworks.com/

Re: Solr query with more than one field

Posted by Alexandre Rafalovitch <ar...@gmail.com>.
Function queries:
https://cwiki.apache.org/confluence/display/solr/Function+Queries
The function would be sub
Then you want its result mapped to a fq. could probably be as simple
as fq={!func}sub(value,cost).

Because the value of the function will be treated as a relevance value
and relevance value of 0 (and less?) will cause the record to be
filtered out.

Regards,
   Alex.
----
http://www.solr-start.com/ - Resources for Solr users, new and experienced


On 1 June 2017 at 13:46, Mikhail Ibraheem
<mi...@yahoo.com.invalid> wrote:
> Hi,I have 2 fields "cost" and "value" at my records. I want to get all documents that have "value" greater than "cost". Something likeq=value:[cost TO *]
> Please advise.
> Thanks