简体   繁体   中英

Apache Solr search a string in the entire collection without specifying the field name

I am looking for a way to search the given string in the entire collection. I referred Correct use case of String parameter in SetQuery function of SolrQuery?

The provided example works for the scenario like this: query.setQuery("fieldName":"value") but it is not working for query.setQuery("*value*") . In my case, I don't want to provide the name of the field and it should search the entire collection no matter the field name which has this value. Is there any other way for this scenario?

Create a copy field named "text" in the schema.xml and copy all the fields to it.

<copyField source="field1" dest="text"/>

In order to set default search field in solrconfig.xml file under /query request handler or as IntParams.

<requestHandler name="/query" class="solr.SearchHandler">
   <lst name="defaults">
     <str name="echoParams">explicit</str>
     <str name="wt">json</str>
     <str name="indent">true</str>
     <str name="df">text</str>
   </lst>
</requestHandler>

<initParams path="/update/**,/query,/select,/tvrh,/elevate,/spell,/browse">
  <lst name="defaults">
    <str name="df">text</str>
  </lst>
</initParams>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM