Question

How to search multiple value against multiple field in solr ?

My scenario :

Currently in schema.xml, i am using <solrQueryParser defaultOperator="AND"/> and

<copyField source="COL1" dest="defaultsearch"/>
<copyField source="COL2" dest="defaultsearch"/>

and

<fieldType name="text_search" class="solr.TextField" positionIncrementGap="100">
 <analyzer>
   <tokenizer class="solr.WhitespaceTokenizerFactory" />
   <filter class="solr.LowerCaseFilterFactory" />      
 </analyzer>
</fieldType>

and

<defaultSearchField>defaultsearch</defaultSearchField>

Example:

My search query is like q=Good Boy.

I have to fetch the records like both Good and Boy should present in either COL1 or COL2.

But for me it gives the result as expected with additional results like Good present in COL1 and Boy present in COL2 or Good present in COL2 and Boy present in COL1.

Please suggest me how to find the results with both Good and Boy should present in either COL1 or COL2.

Was it helpful?

Solution

if you require exact match on COL1 and COL2, then you can execute the following (assuming COL1 and COL2 are strings) :-

q=(COL1:"Good Boy" OR COL2:"Good Boy")

If you do not require exact match and the phrase should contain both "Good" and "Boy" in any order, then try the following (untested) :-

q=(COL1:*Good Boy* OR COL2: *Good Boy*) 
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top