solr聯合多個字段進行檢索(multivalued和copyfield的使用)
阿新 • • 發佈:2017-08-23
-1 strong str lang img ring index 技術 字符
copyField 與multiValued用途
在我們的應用中經常會有這種情形:當用戶輸入某個字符串查找時,需要如果在標題及內容中存在這個字會串時均要把記錄加載出來,通過引入copyField及multiValue這兩個標簽便可解決這種問題。如:
<!--這裏無需定義id,因為managed_schema文件已經在前面開頭位置定義了,id是必須,並且唯一的--> <field name="S_user" type="string" indexed="true" stored="true"/> <field name="S_text" type="string" indexed="true" stored="true"/>
<field name="sgk" type="string" indexed="true" stored="false" multiValued="true"/> <!--CopyField復制域,功能就是在添加文檔的時候自動的把源域的內容復制到目標域。可以把目標域作為默認搜索域可以提高查詢的性能。 Source:源域 Dest:目標域--> <copyField source="S_user" dest="sgk" /> <copyField source="S_text" dest="sgk" />
1.首先也要定義目標域的屬性,name域名=sgk,type類型,indexed是否索引,stored是否存儲(不存儲,這裏只到連接的作用),multiValued=true
<copyField source="S_user" dest="sgk" /> <copyField source="S_text" dest="sgk" />
把S_user和S_text用sgk聯合和進行檢索
從上圖看出sgk區域,是s_user、s_texte 兩個的集合,無論搜索s_user、s_texte 中任意一個,都能通過sgk搜索出來
solr聯合多個字段進行檢索(multivalued和copyfield的使用)