Solr4 currently only looks at the default "df" field, how can we search multiple fields?
Asked Answered
H

2

5

In Solr 4, I see that we've configured the default field "df" in the /select request handler:

  <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">id</str>

But id is our unique document field, so all queries are defaulting to "id:my_query", which always returns 0 results.

How do I define which fields should be queried by default?

This is an upgrade from v3 to v4 and this part of it seems to have been broken along the way.

Hyperactive answered 6/3, 2013 at 8:4 Comment(0)
C
10

You can use a copy field named "text", 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">text</str>

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

<copyField source="field1" dest="text"/>
<copyField source="field2" dest="text"/>
...
<copyField source="fieldn" dest="text"/>

Note that "text" is the copy field here.

Catawba answered 6/3, 2013 at 8:9 Comment(3)
How do I copy multiple (but not all) fields, i.e., is this correct: <copyField source="field1,field2" dest="allsearchable"/>, and I presume you have to configure the field "allsearchable" in the same way that other fields are configured right?Hyperactive
There's a problem with this method though if you have different field types (that then have different tokenizers) of the source fields that you're copying to "text". Meaning, when you search against text, only the tokenizers applied to the field type of "text" will be applied.Wilmawilmar
@ChrisDrumgoole, I agree with your point that all descriptive values of the fields will be lost once copied to default "text" field. What would be the right approach to solve this?Colorific
O
2

you can use edismax search.

See https://cwiki.apache.org/confluence/display/solr/The+Extended+DisMax+Query+Parser

Check the qf(query field) parameter. You can pass multiple fields to it

Oreste answered 3/11, 2014 at 13:41 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.