在INNER JOIN中

时间:2016-03-29 18:39:38

标签: apache solr lucene

我正在尝试配置Solr以允许来自我的数据库的查询数据。在我配置它之后,我添加了一个新字段,它是另一个表的外键。

旧记录将此字段设为NULL。

架构数据库

表:优惠

字段:id,type_material(外键),(其他字段不需要显示)

表:材料

字段:id,name

Solr config

文件db-data-config.xml:

<dataConfig>
    <dataSource type="JdbcDataSource" driver="com.mysql.jdbc.Driver" url="jdbc:mysql://path" user="user" password="pwd" />
    <document name="offers">
       <entity name="offers"
                 query="SELECT o.* FROM offers o inner join offer_group g on o.offer_group_id = g.id where g.status = 0"
                 deltaQuery="select id from offers where updated_at > '${dataimporter.last_index_time}'">

          <field column="id" name="id" />
          <field column="product_code" name="product_code" />
          <field column="gender" name="gender" />
          <field column="colors" name="colors" />
          <field column="year" name="year" />
          <field column="tags" name="tags" />
          <field column="size" name="size" />
          <field column="size_typology" name="size_typology" />
          <field column="season" name="season" />
          <field column="quantity" name="quantity" />
          <field column="price" name="price" />
          <field column="typology" name="typology" />
          <field column="model" name="model" />

          <entity name="brands"
                    query="select name from brands where id='${offers.brand_id}'"
                    deltaQuery="select id from brands where updated_at > '${dataimporter.last_index_time}'" >
               <field name="brand_name" column="name" />
          </entity>

          <entity name="materials"
                    query="select name from materials where id='${offers.type_material}' OR '${offers.type_material}' = NULL">
                <field name="material_name" column="name" />
          </entity>

          <entity name="offer_group"
                    query="select shop_id from offer_group where id='${offers.offer_group_id}'"
                    deltaQuery="select id from offer_group where updated_at > '${dataimporter.last_index_time}'" >
               <field name="shop_id" column="shop_id" />
          </entity>

       </entity>
    </document>
</dataConfig>

文件schema.xml:

<?xml version="1.0" encoding="UTF-8" ?>
<schema name="offers" version="1.5">
    <fieldType name="string" class="solr.StrField"></fieldType>
    <fieldType name="boolean" class="solr.BoolField" sortMissingLast="true"/>
    <fieldType name="int" class="solr.TrieIntField" precisionStep="0" positionIncrementGap="0"/>
    <fieldType name="float" class="solr.TrieFloatField" precisionStep="0" positionIncrementGap="0"/>
    <fieldType name="long" class="solr.TrieLongField" precisionStep="0" positionIncrementGap="0"/>
    <fieldType name="double" class="solr.TrieDoubleField" precisionStep="0" positionIncrementGap="0"/>
    <fieldType name="date" class="solr.TrieDateField" precisionStep="0" positionIncrementGap="0"/>

    <!-- Just like text_general except it reverses the characters of
     each token, to enable more efficient leading wildcard queries. -->
    <fieldType name="text_general" class="solr.TextField" positionIncrementGap="100">
        <analyzer type="index">
            <tokenizer class="solr.StandardTokenizerFactory"/>
            <filter class="solr.StandardFilterFactory"/>
            <filter class="solr.ASCIIFoldingFilterFactory" />
            <filter class="solr.LowerCaseFilterFactory"/>
            <filter class="solr.ReversedWildcardFilterFactory" withOriginal="true"
                    maxPosAsterisk="3" maxPosQuestion="2" maxFractionAsterisk="0.33" minTrailing="3" />
            <filter class="solr.EdgeNGramFilterFactory" minGramSize="1" maxGramSize="15" />
        </analyzer>
        <analyzer type="query">
            <tokenizer class="solr.StandardTokenizerFactory"/>
            <filter class="solr.ASCIIFoldingFilterFactory" />
            <filter class="solr.StandardFilterFactory"/>
            <filter class="solr.LowerCaseFilterFactory"/>
        </analyzer>
    </fieldType>

    <fieldType name="random" class="solr.RandomSortField" indexed="true" />

    <dynamicField name="random_*" type="random" indexed="true" stored="false"/>
    <!-- End randomize offers-->

    <field name="_version_" type="long" indexed="true" stored="true" required="false"/>
    <field name="id" type="long" indexed="true" stored="true" required="true" />
    <field name="brand_id" type="long" indexed="true" stored="true" required="true" />
    <field name="shop_id" type="long" indexed="true" stored="true" required="true" />
    <field name="brand_name" type="text_general" indexed="true" stored="true" required="true" />

    <field name="type_material" type="long" indexed="true" stored="true" default="NULL" />
    <field name="material_name" type="text_general" indexed="true" stored="true" default="NULL" />

    <field name="offer_group_id" type="long" indexed="true" stored="true" required="true" />
    <field name="product_code" type="text_general" indexed="true" stored="true" default="NULL" />
    <field name="gender" type="string" indexed="true" stored="true" default="NULL" />
    <field name="colors" type="text_general" indexed="true" stored="true" default="NULL" />
    <field name="year" type="text_general" indexed="true" stored="true" default="NULL" />
    <field name="tags" type="text_general" indexed="true" stored="true" default="NULL" />
    <field name="size" type="string" indexed="true" stored="true" default="NULL" />
    <field name="size_typology" type="string" indexed="true" stored="true" default="NULL" />
    <field name="season" type="text_general" indexed="true" stored="true" default="NULL" />
    <field name="quantity" type="string" indexed="true" stored="true" default="NULL" />
    <field name="price" type="float" indexed="true" stored="true" default="NULL" />
    <field name="typology" type="text_general" indexed="true" stored="true" default="NULL" />
    <field name="photo_url" type="string" indexed="true" stored="true" required="true" />
    <field name="model" type="text_general" indexed="true" stored="true" default="NULL" />
    <field name="created_at" type="date" indexed="true" stored="true"/>
    <field name="updated_at" type="date" indexed="true" stored="true"/>

    <field name="text" type="text_general" indexed="true" stored="false" multiValued="true"/>

    <uniqueKey>id</uniqueKey>

    <copyField source="colors" dest="text"/>
    <copyField source="year" dest="text"/>
    <copyField source="season" dest="text"/>
    <copyField source="typology" dest="text"/>
    <copyField source="model" dest="text"/>
    <copyField source="tags" dest="text"/>
    <copyField source="product_code" dest="text"/>
    <copyField source="brand_name" dest="text"/>
  <copyField source="material_name" dest="text" />
    <copyField source="gender" dest="text"/>
</schema>

当搜索的查询开始时,返回所有 type_material 的字段等于NULL的商品。

我也要重试那些。

1 个答案:

答案 0 :(得分:0)

只需使用过滤查询&fq=type_material:NULL

即可