Search code examples
solrlucenelucene.netsolrj

Solr 7.3 is indexing fine - but returns 0 result on searching


My question is same as this - Solr Index appears to be valid - but returns no results but for newly announced solr 7.3.

I have created a Solr index and write a whole bunch of docs into it. I can see from the Solr admin page that the docs exist and the schema is fine as well. But when I perform a search using a test keyword I do not get any results back.

On entering * : * into the query (in Solr admin page) I get all the results.

However, when I enter any other query (e.g. a term or phrase) I get no results. I have verified that the field being queried is Indexed and contains the values I am searching for.

Solr 7.3 however have removed the <defaultSearchField> in the new release. Is there any alternate solution? How to make it search and return results from all documents?


Solution

  • So starting from solr 7.3 , the support for default field has removed.

    see here https://lucene.apache.org/solr/guide/7_3/major-changes-in-solr-7.html?hl=defaultSearchField#other-deprecations-and-removals

    Now when you do not specify a field while searching there is no default field to search on. The only way to do it is using the df operator. So in your case if you want that if the field is not specified then you wnat to search in the category field then use the following query:

    q=https://ip:port/select?q=apple&wt=json&df=category

    so you need to specify the default field in the query itself.

    Now the question to if you want to search in all the fields. you can use the copyField.

    So you can create a copy field in you scheam file. copy all the fields whcih you want to search when nothing is specified and then use that field in the df.

    e.g define a field called text in your schema

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

    Now define some copy fields for this.

     <copyField source="category" dest="_text_" />
     <copyField source="first_name" dest="_text_" />
    

    and then in your queries you can do like this

    q=https://ip:port/select?q=apple&wt=json&df=_text_

    Read more about copy fileds here : https://lucene.apache.org/solr/guide/7_3/copying-fields.html

    Be aware though copying field is duplicating data and it will increase your index size.