Apache Solr一对多关系映射

时间:2015-09-30 12:00:32

标签: solr lucene dataimporthandler

我在db-config.xml

中配置了以下内容
<dataConfig>
  <dataSource type="JdbcDataSource"
            driver="com.mysql.jdbc.Driver"
            url="jdbc:mysql://host:port/schema"
            user="username"
            password="password" /> 

   <document name="product">
    <entity name="store" query="select mid,name,display_name,address,email,pincode,b.latitude,b.longitude,city,locality,b.lid,b.locid from business b join locality loc on b.locid = loc.locid join location l on l.lid = loc.lid where b.status='A' and isItemStore ='Y' and mid between  11151 and 11161 ">
        <field column="mid" name="id"/>
        <field column="lid" name="lid"/>
        <field column="locid" name="locid"/>
        <field column="name" name="name"/>
        <field column="display_name" name="display_name"/>
        <field column="address" name="address"/>
        <field column="email" name="email"/>
        <field column="pincode" name="pincode"/>
        <field column="latitude" name="latitude"/>
        <field column="longitude" name="longitude"/>
        <field column="city" name="city"/>
        <field column="locality" name="locality"/>

        <entity name="item" query="select ib.cid,ib.bid,ib.item_id,b.bname,c.cname,ib.description,short_description,
    concat(field_1,' ',field_2,' ',field_3,' ',field_4,' ',field_5,' ',field_6) item_feature,inv.pos_code,sku_count,unit_price,final_price from item_business ib join brand b on ib.bid = b.bid join category c on c.cid=ib.cid join `${store.mid}-inventory-table` inv where ib.status='A'"> 
               <field column="item_id" name="item_id"/>     
               <field column="short_description" name="short_description"/>
               <field column="item_desc" name="item_desc"/>
               <field column="item_feature" name="item_feature"/>
               <field column="bid" name="bid"/>
               <field column="cid" name="cid"/>
               <field column="bname" name="brand_name" />
               <field column="cname" name="category_name" />     
               <field column="pos_code" name="pos_code" />   
               <field column="sku_count" name="sku_count" />     
               <field column="unit_price" name="unit_price" />   
               <field column="final_price" name="final_price" />      
           </entity>
    </entity>
    </document>
</dataConfig>

下面的代码片段是我在schema.xml中的内容

<uniqueKey>id</uniqueKey>     
     <field name="id" type="tlong" indexed="true" stored="true"/>
     <field name="name" type="text_general" indexed="true" stored="true"/>
     <field name="display_name" type="text_general" indexed="true" stored="true"/>
     <field name="address" type="text_general" indexed="true" stored="true"/>
     <field name="email" type="text_general" indexed="true" stored="true"/>
     <field name="pincode" type="text_general" indexed="true" stored="true"/>
    <field name="latitude" type="tdouble" indexed="true" stored="true"/>
    <field name="longitude" type="tdouble" indexed="true" stored="true"/>
    <field name="city" type="text_general" indexed="true" stored="true"/>
    <field name="locality" type="text_general" indexed="true" stored="true"/>
    <field name="item_id" type="tlong" indexed="true" stored="true"/>       
    <field name="bname" type="text_general" indexed="true" stored="true"/>
    <field name="cname" type="text_general" indexed="true" stored="true"/>
    <field name="item_feature" type="text_general" indexed="true" stored="true"/>
    <field name="item_desc" type="text_general" indexed="true" stored="true"/>
    <field name="short_description" type="text_general" indexed="true" stored="true"/>
    <field name="pos_code" type="text_general" indexed="true" stored="true"/>    
    <field name="sku_count" type="tint"    indexed="true"  stored="true"/> 
    <field name="unit_price" type="tdouble"    indexed="true"  stored="true"/> 
    <field name="final_price" type="tdouble"    indexed="true"  stored="true"/>

solrconfig.xml中

 <lib dir="../../../dist/" regex="solr-dataimporthandler-\d.*\.jar" />

   <requestHandler name="/dataimport"  class="org.apache.solr.handler.dataimport.DataImportHandler">
    <lst name="defaults">
        <str name="config">db-data-config.xml</str>
    </lst>
   </requestHandler

我是Apache Solr的初学者。我跟着Solr wiki来启动我的服务器并运行Jetty服务器。

场景:商店中的商品和商品都有属性。

我获取商店信息,然后在商店中获取商店所拥有的商品。

但索引仅针对一个商店和一个商品而不是一个商店以及一个商店中的所有商品进行。

db-config.xml中的第二个查询如何多次运行以获取该商店的所有商品?

我看到有一个多值选项,但我不确定如何在这种情况下使用它。

有人能帮忙吗?

0 个答案:

没有答案