Solr长多值字段不起作用

时间:2015-09-02 14:26:59

标签: java solr lucene

我有一个solr实体,其定义为:

<field name="rel_ids" type="long" indexed="true" stored="true" multivalue="true" />

然后我用数据导入处理程序填充它:像这样

<field column="rel_ids" sourceColName="rel_idsc" splitBy=","/>

但我无法搜索此字段,例如以下查询无效:

rel_ids:1 - &gt;没有结果

rel_ids:* - &gt;没有结果

这是我的完整架构:

<schema name="example" version="1.5">
<fields>
    <field name="id" type="long" indexed="true" stored="true" required="true" />
    <field name="id_S100" type="long" indexed="true" stored="true" required="false" />
    <field name="id_S95" type="long" indexed="true" stored="true" required="false" />
    <field name="id_S90" type="long" indexed="true" stored="true" required="false" />
    <field name="id_None" type="long" indexed="true" stored="true" required="false" />
    <field name="text" type="text_ar" indexed="true" stored="true" />
    <field name="text_noStem" type="text_ar_noStem" indexed="true" stored="true" />
    <field name="text_noStem_withHarekat" type="text_ar_noStem_withHarekat" indexed="true" stored="true" />

    <field name="source_book" type="string" indexed="true" stored="true" />
    <field name="source_volume" type="string" indexed="true" stored="true" />
    <field name="source_page" type="int" indexed="true" stored="true" />
    <field name="rel_ids" type="long" indexed="true" stored="true" multiValued="true" />
    <field name="_version_" type="long" indexed="true" stored="true"/>
</fields>
<uniqueKey>id</uniqueKey>
<copyField source="text" dest="text_noStem" />
<copyField source="text" dest="text_noStem_withHarekat" />

 <types>
<!-- field type definitions. The "name" attribute is
   just a label to be used by field definitions.  The "class"
   attribute and any other attributes determine the real
   behavior of the fieldType.
     Class names starting with "solr" refer to java classes in a
   standard package such as org.apache.solr.analysis
-->

<!-- The StrField type is not analyzed, but indexed/stored verbatim. -->
<fieldType name="string" class="solr.StrField" sortMissingLast="true" />

<!-- boolean type: "true" or "false" -->
<fieldType name="boolean" class="solr.BoolField" sortMissingLast="true"/>

<!-- sortMissingLast and sortMissingFirst attributes are optional attributes are
     currently supported on types that are sorted internally as strings
     and on numeric types.
     This includes "string","boolean", and, as of 3.5 (and 4.x),
     int, float, long, date, double, including the "Trie" variants.
   - If sortMissingLast="true", then a sort on this field will cause documents
     without the field to come after documents with the field,
     regardless of the requested sort order (asc or desc).
   - If sortMissingFirst="true", then a sort on this field will cause documents
     without the field to come before documents with the field,
     regardless of the requested sort order.
   - If sortMissingLast="false" and sortMissingFirst="false" (the default),
     then default lucene sorting will be used which places docs without the
     field first in an ascending sort and last in a descending sort.
-->    

<!--
  Default numeric field types. For faster range queries, consider the tint/tfloat/tlong/tdouble types.
-->
<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"/>
...

我的数据导入处理程序字段匹配:

   <dataConfig>
<dataSource type="JdbcDataSource" driver="com.mysql.jdbc.Driver" url="jdbc:mysql://localhost/hadithtest" user="root" password="root"/>
<document name="Hadiths" >
<entity name="hadith" transformer="RegexTransformer"  query="SELECT ..." >
    <field name="id" column="id" />
    <field name="text" column="basetext" />
    <field name="source_book" column="source_bookglossary" />
    <field name="source_volume" column="source_volumestring" />
    <field name="source_page" column="source_pagestring" />
    <field name="id_None" column="id_None" />
    <field name="id_S100" column="id_S100" />
    <field name="id_S95" column="id_S95" />
    <field name="id_S90" column="id_S90" />
    <field column="aye_ids" sourceColName="aye_idsc" splitBy="\s+"/>
    <field name="aye_ids_text" column="aye_idsc" />
   <!--
    <field name="TextID" column="text_id" />
    <entity name="RText" query="select * from richtext where richtext.id='${hadith.TextID}'" >
        <field name="Text" column="text" />
    </entry>
    -->
</entity>

    

任何人都可以帮忙解决这个问题吗? (我无法查询rel_ids

1 个答案:

答案 0 :(得分:1)

我算错了!

问题是我没有在dataImport transformer标记中指定entity

所以数据导入应该是这样的:

<dataConfig>
<dataSource type="JdbcDataSource" driver="com.mysql.jdbc.Driver" url="jdbc:mysql://localhost/hadithtest" user="root" password="root"/>
<document name="Hadiths" >
<entity name="hadith" transformer="RegexTransformer"  query="SELECT ..." >
    <field name="id" column="id" />
    <field name="text" column="basetext" />
    <field name="source_book" column="source_bookglossary" />
    <field name="source_volume" column="source_volumestring" />
    <field name="source_page" column="source_pagestring" />
    <field name="id_None" column="id_None" />
    <field name="id_S100" column="id_S100" />
    <field name="id_S95" column="id_S95" />
    <field name="id_S90" column="id_S90" />
    <field column="aye_ids" sourceColName="aye_idsc" splitBy="\s+"/>
    <field name="aye_ids_text" column="aye_idsc" />
   <!--
    <field name="TextID" column="text_id" />
    <entity name="RText" query="select * from richtext where richtext.id='${hadith.TextID}'" >
        <field name="Text" column="text" />
    </entry>
    -->
</entity>
</document>
</dataConfig>