0
votes

Solr does not return the results until I prefix the :field name for example I am searching for Ajay,I need to prefix name:Ajay to get the results.I tried the copy tag.But it does not seem to return the results.Can you please tell me what can I change other than the below change.

<copyField source="name" dest="text"/>
<copyField source="last_name" dest="text"/>
2

2 Answers

2
votes

The old way this was configured was with <defaultSearchField> in schema.xml. This indicates the field searched by default if no other field is included in the query.

You may want to either use the df parameter in the query (or as the other answer says, add it as a default value), or if you're using the (e)dismax handler (which you probably are), use the qf parameter to indicate which fields to query and the weights between the different fields.

q=Ajay&qf=text&defType=edismax

.. should do what you want.

1
votes

If you look at your solrconfig.xml file, you will see that the /select requestHandler is configured with the default search field as:

<lst name="defaults">
  <str name="df">aField</str>
</lst>

Here, you can put the field that you want like for example:

<lst name="defaults">
  <str name="df">name</str>
</lst>

You can see another topic about this subject and the Solr Documentation.

To build a searcheable field, in your schema.xml, you can create a new field:

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

After that, you can copy the fields that you want in your new field:

<copyField source="name" dest="searchable_field"/>
<copyField source="last_name" dest="searchable_field"/>
<copyField source="birthday" dest="searchable_field"/>
<copyField source="location" dest="searchable_field"/>

And to finish, you just have to put this new field in your solrconfig.xml:

<lst name="defaults">
  <str name="df">searchable_field</str>
</lst>