March 21, 2020
Estimated Post Reading Time ~

How to search in entire Solr fields for a query?

How to search in entire solr fields?
We have many levels of configurations for Solr, which makes Solr a rich search tool. Usually, we do search the Solr with respect to a specific field which is defined in schema.xml. But there are cases we need to search across multiple fields. Let us see how it can be achieved.

There are two ways to do this.

1. Using DisMax: Usually, Solr comes with dismax plugin. So in the query, we just need to pass all fields in the QF field as shown below.

/select?defType=dismax&q="query1","query2","query3"&qf=field1 field2 field3

In the above case, we are searching 3 terms query1,query2,query3 (added in inverted commas to ensure words with space fetch matching results)
field1,2,3 are the fields in schema.xml to be searched.

2. Another way is collecting all data to the same field by copying through schema.xml

We need to have below lines in schema files,

<field name="datacollection" type="text_general" indexed="true" stored="false" multiValued="true"/>

Then copy the contents of required fields to the new field

<copyField source="field1" dest="datacollection"/>
<copyField source="field2" dest="datacollection"/>
<copyField source="field3" dest="datacollection"/>

Then query in default field data collection.


By aem4beginner

No comments:

Post a Comment

If you have any doubts or questions, please let us know.