siva
siva

Reputation: 1145

solr 8.2 search across fields with df

I have a collection with 5 fields say a,b,c,d,e. currently it works like q=a:value but I want to search across fields (like q=value)

I tried the below in the solrConfig.xml but no luck.Appreciate any pointers

<initParams path="/update/**,/query,/select,/tvrh,/elevate,/spell,/browse">
    <lst name="defaults">
      <str name="df">text1</str>
    </lst>
<copyField source="a" dest="text1" indexed="true" stored="true"/>
<copyField source="b" dest="text1" indexed="true" stored="true"/>
<copyField source="c" dest="text1" indexed="true" stored="true"/>
<copyField source="d" dest="text1" indexed="true" stored="true"/>
<copyField source="f" dest="text1" indexed="true" stored="true"/>
  </initParams>

<fields>
<copyField source="a" dest="text1" indexed="true" stored="true"/>
<copyField source="b" dest="text1" indexed="true" stored="true"/>
<copyField source="c" dest="text1" indexed="true" stored="true"/>
<copyField source="d" dest="text1" indexed="true" stored="true"/>
<copyField source="f" dest="text1" indexed="true" stored="true"/>

</fields>

Upvotes: 0

Views: 441

Answers (2)

MatsLindh
MatsLindh

Reputation: 52802

Use the edismax query parser and supply the qf parameter. It'll also allow you to boost hits in each field differently. qf=a^5 b will give hits in the a field five times more weight than hits in the b field.

Since the field specification is in the qf argument now, the q parameter can be used as a more simple user typed query instead - q=foo bar.

Upvotes: 2

Abhijit Bashetti
Abhijit Bashetti

Reputation: 8658

You can use a copy field named "text1", copy all your searchable fields into this field and specify it as default search field.

<requestHandler name="/select" class="solr.SearchHandler">
    <!-- default values for query parameters can be specified, these
         will be overridden by parameters in the request
      -->
     <lst name="defaults">
       <str name="echoParams">explicit</str>
       <int name="rows">10</int>
       <str name="df">text1</str>

Add the field in the schema.xml

<fields> 
   <field name="a" type="string" indexed="true" stored="true" required="true" /> 
   <field name="b" type="string" indexed="true" stored="true" required="true" /> 
   .
   .
  <field name="text1" type="text" indexed="true" stored="false" multiValued="true" /> 
</fields>

You can add fields to be copied to a copy field as follows:

<copyField source="a" dest="text1"/>
<copyField source="b" dest="text1"/>
...
<copyField source="e" dest="text1"/>

Upvotes: 0

Related Questions