在Solr中,是否可以通过两个不同的词语在两个字段中进行搜索,并仅返回包含这两个词语的结果?
例如,假设我有“type”和“location”两个字段,我只想要那些同时拥有type='furniture'和location='office'的结果。
在Solr中,是否可以通过两个不同的词语在两个字段中进行搜索,并仅返回包含这两个词语的结果?
例如,假设我有“type”和“location”两个字段,我只想要那些同时拥有type='furniture'和location='office'的结果。
您可以使用布尔运算符并在单个字段上搜索。
q=type:furniture AND location:office
如果值是固定的,最好使用过滤查询以提高性能。
fq=type:furniture AND location:office
<requestHandler name="/combine" class="solr.SearchHandler" default="false">
<lst name="invariants">
<str name="q">
(_query_:"{!edismax qf='type' v=$uq1}"
AND _query_:"{!edismax qf='location' v=$uq2}")
</str>
</lst>
</requestHandler>
http://localhost:8983/solr/collection1/combine?uq1=furniture&uq2=office
解释
Solr文档
type=dismax&bq=type:furniture AND location:office
fq=type:furniture AND location:office
可以将其拆分为两个过滤查询,而不是使用AND。
fq=type:furniture
fq=location:office
fq=
,因为这可以更快地实现。 - Michael Dillon