solr - set fileds as default search field

时光怂恿深爱的人放手 提交于 2019-12-01 07:16:48

问题


The following query works well for me

http://[]:8983/solr/vault/select?q=VersionComments%3AWhite

returns all the documents where version comments includes White

I try to omit the field name and put it as a default value as follows : In solr config I write

<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">PackageName</str>
   <str name="df">Tag</str>
   <str name="df">VersionComments</str>
   <str name="df">VersionTag</str>
   <str name="df">Description</str>
   <str name="df">SKU</str>
   <str name="df">SKUDesc</str>
 </lst>

I restart the solr and create a full import.
Then I try using

 http://[]:8983/solr/vault/select?q=White  

(Where

 http://[]:8983/solr/vault/select?q=VersionComments%3AWhite

still works)

But I dont get the document any as answer.
What am I doing wrong?


回答1:


As far as I know you should only have the <str name="df"></str> declared once in your requestHandler

Typically what I do is copy all the fields that i want to search into a default search field called text.

schema.xml:

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

solrconfig.xml

<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="q">*:*</str>
   <str name="echoParams">explicit</str>
   <int name="rows">10</int>
   <str name="df">text</str>
</lst>
</requestHandler>

If this is not good enough, you can always search other fields using a dismax search with the qf declaration like so:

http://localhost:8983/solr/vault/select/?q= White&defType=dismax&qf=PackageName+Tag+VersionComments+VersionTag+Description+SKU+SKUDesc



来源:https://stackoverflow.com/questions/17927992/solr-set-fileds-as-default-search-field

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!