solr copyfield字段使用實踐


  1、使用場景

    比如我們現在有一個文檔,有title、author、area、keyword、link等字段。現在要把這個文檔索引到 solr中,為了方便對author、area、keyword進行搜索,我們定義一個author_area_keyword的字段,

    把author、area、keyword的內容都拷貝到author_area_keyword字段中,這樣copyfield就派上了用場,這樣在創建文檔的同事,三個字段的內容自動就復制到author_area_keyword中了。

    

 

  2、修改配置文件managed-schema

    語法:<copyField source=”” dest=””>

    source:原來的域。也就是你想要復制的域

    dest(destination):目標域。也就是要復制到那個字段。

    需要注意的是author_area_keyword字段要設置multiValued="true"

<field name="title" type="text_mmseg4j_simple" indexed="true" stored="true"/>
  <field name="author" type="string" indexed="true" stored="true"/>
  <field name="area" type="string" indexed="true" stored="true"/>
  <field name="keyword" type="string" indexed="true" stored="true"/>
  <field name="link" type="string" indexed="true" stored="true"/>
  <field name="author_area_keyword" type="string" multiValued="true" indexed="true" stored="false"/>
  <copyField source="area" dest="author_area_keyword"/>
  <copyField source="author" dest="author_area_keyword"/>
  <copyField source="keyword" dest="author_area_keyword"/>

  3、導入文件

    java -jar -Dc=data -Dauto post.jar ..\Import\*

 

  4、查詢

    

    

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM