[英]Solr search query over multiple fields
是否可以使用兩個不同的單詞在Solr中搜索兩個字段並僅返回包含它們的結果?
例如,如果我有字段“type”和“location”,我只想要那些在其中包含type ='furniture'和location ='office'的結果。
您可以使用布爾運算符並搜索單個字段。
q=type:furniture AND location:office
如果值已修復,則最好使用“篩選查詢性能”。
fq=type:furniture AND location:office
建議的解決方案有一個缺點,你必須關心轉義特殊字符。 如果用戶搜索“type:d'或AND location:coffee break”,則查詢將失敗。
我建議結合兩個edismax處理程序:
<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 Docs
您還可以使用dismaxRequest處理程序上的boostQuery函數作為
type=dismax&bq=type:furniture AND location:office
fq=type:furniture AND location:office
而不是使用AND,這也可以分成兩個過濾查詢。
fq=type:furniture
fq=location:office
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.