solr的multivalued使用說明

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

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

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

  1.  
    <fields>
  2.  
    <!-- general -->
  3.  
    <field name="id" type="int" indexed="true" stored="true" multiValued="false" required="true"/>
  4.  
    <field name="planTime" type="tdate" indexed="true" stored="false" multiValued="false" />
  5.  
    <field name="state" type="string" indexed="true" stored="false" multiValued="false" />
  6.  
    <field name="overDate" type="string" indexed="true" stored="false" multiValued="false" />
  7.  
    <field name="type" type="int" indexed="true" stored="false" multiValued="false" />
  8.  
    <field name="contactName" type="textComplex" indexed="true" stored="false" multiValued="false" />
  9.  
    <field name="contactTel" type="string" indexed="true" stored="false" multiValued="false" />
  10.  
    <field name="customer" type="textComplex" indexed="true" stored="false" multiValued="false" />
  11.  
    <field name="alias" type="textComplex" indexed="true" stored="false" multiValued="false" />
  12.  
    <field name="englishName" type="textComplex" indexed="true" stored="false" multiValued="false" />
  13.  
    <field name="executor" type="int" indexed="true" stored="true" multiValued="true" />
  14.  
    <!--[1m~K[1m~][1m~W段-->
  15.  
    <field name="keywords" type="text" indexed="true" stored="false" multiValued="true"/>
  16.  
    </fields>

     其中:code

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

 

    最後看下查詢效果:xml

    

       從上圖看書,executor這個field能夠多個值,任何executor:29 OR executor:40,相似查詢都能查出id爲3的記錄索引

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

  1.  
    @Field
  2.  
    private Set<Integer> executor;
  3.  
     
  4.  
    public Set<Integer> getExecutor() {
  5.  
    return executor;
  6.  
    }
  7.  
     
  8.  
    public void setExecutor(Set<Integer> executor) {
  9.  
    this.executor = executor;
  10.  
    }

       

 

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

       

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

相關文章
相關標籤/搜索