如何搜索SOLR中包含关键字的所有字段?
问题描述:
例如,我搜索的关键词是:'Basket Ball'。什么是可以获得包含'Basket Ball'的所有字段的查询。 我试过使用*:Basket Ball,但它不起作用。如何搜索SOLR中包含关键字的所有字段?
答
schema.xml中定义了默认的搜索字段 -
<defaultSearchField>text</defaultSearchField>
您可以复制所有字段此默认搜索字段。
<copyField source="field1" dest="text"/>
<copyField source="field2" dest="text"/>
<copyField source="field3" dest="text"/>
和查询q=basket ball
应该工作。
答
您需要使用能够将令牌分派给多个字段的查询解析器,例如(e)dismax。对于为例,如果你有两个字段field1
和field2
:http://solr/select?q={!dismax}Basket Ball&qf=field1^1 field2^1
对dismax配置的详细信息,请参阅http://wiki.apache.org/solr/DisMaxQParserPlugin#qf_.28Query_Fields.29。
答
默认的搜索字段(自3.6)现在solrconfig.xml中定义
例如在附带的Solr configsets目录,你会看到类似
<initParams path="/update/**,/query,/select,/tvrh,/elevate,/spell">
<lst name="defaults">
<str name="df">allText</str>
</lst>
</initParams>
你可以改变solrconfig.xml中allText
到yourDefaultSearchFieldName
自Solr 3.6及更高版本以来,这已不再适用。这样做后查看https://issues.apache.org/jira/browse/SOLR-2724 – kellyfj