Reputation: 603
My solr implementation has query something like this
q=(field1:ipod and field2:black) OR (field3:'apple computers') OR (field4:working)
There are essentially 3 conditions here separated by 'OR'. When i run this query i get the results. In the results i would like to see which of the 3 conditions were met. For example in the results in addition to the returned data (custom fields), specifically I would like to have cond1=true, cond2=true, cond3=false for each of the document returned.
Assume that there are no analysis will be done on these fields(1 to 4). All fields are string. Solr 4.6.1. Distributed.
Solutions tried (but without satisfactory results):
Any other options solutions here? should i write custom similarity or custom Doc transformer here?
Upvotes: 1
Views: 908
Reputation: 11023
Taking hint from https://cwiki.apache.org/confluence/display/solr/Function+Queries
you could use the following fl
param in your query:
fl=*,firstmatch:if(and(termfreq(field1,'ipod'),termfreq(field2,'black')),1,0),
secondmatch:if(termfreq(field3,'apple computer')),1,0),
thirdmatch:if(termfreq(field4,'working'),1,0)
(the new lines are only for clarity)
That should give you three fields with 1 or 0 for matches.
Basic idea is you can use function queries in fl
field to get specific values. The names firstmatch
, secondmatch
and thirdmatch
are simply aliases.
BTW, since you mention all your fields are strings, you will need exact matches everywhere.
Upvotes: 0