solr multivalued

http://blog.csdn.net/alen1985/article/details/8538942

solr的schema.xml配置文件在配置Filed的時候,有個屬性:

       MutiValued:true if this field may containmutiple values per documents,這個說明有點模糊,下面結合實際應用,列舉兩個不同的例子。

       例子一:一個field有多個值,值來自同一filed

 <fields>
  <!-- general -->
  <field name="id"      type="int"      indexed="true"  stored="true"  multiValued="false" required="true"/>
  <field name="planTime"    type="tdate"   indexed="true"  stored="false"  multiValued="false" />
  <field name="state"   type="string"   indexed="true"  stored="false"  multiValued="false" />
  <field name="overDate"   type="string"   indexed="true"  stored="false"  multiValued="false" />
  <field name="type"   type="int"   indexed="true"  stored="false"  multiValued="false" />
  <field name="contactName"   type="textComplex"   indexed="true"  stored="false"  multiValued="false" />
  <field name="contactTel"    type="string"   indexed="true"  stored="false"  multiValued="false" />
  <field name="customer"    type="textComplex"   indexed="true"  stored="false"  multiValued="false" />
  <field name="alias"    type="textComplex"   indexed="true"  stored="false"  multiValued="false" />
  <field name="englishName"    type="textComplex"   indexed="true"  stored="false"  multiValued="false" />
  <field name="executor"    type="int"   indexed="true"  stored="true"  multiValued="true" />
  <!--[1m~K[1m~][1m~W段-->
  <field name="keywords" type="text" indexed="true" stored="false" multiValued="true"/>
</fields>

 其中:

  <field name="executor"    type="int"   indexed="true"  stored="true"  multiValued="true" /

最後看下查詢效果:

    

      從上圖看書,executor這個field可以多個值,任何executor:29 OR executor:40,類似查詢都能查出id爲3的記錄。

     附註:使用solrj建此索引時,定義成集合類型即可,如:

    @Field
    private Set<Integer> executor;
    public Set<Integer> getExecutor() {
        return executor;
    }
    public void setExecutor(Set<Integer> executor) {
        this.executor = executor;
    }

   例子二:類似綜合搜索,結合copyFiled使用,多個Filed拷貝到該Field上

    從上圖看出keywords區域,是name、introduction、industryName三個的集合,無論搜索name、introduction、industryName中任意一個,都能通過keywords搜索出來。


發佈了16 篇原創文章 · 獲贊 5 · 訪問量 15萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章