如何使用单个solr实例或Solr Template字段无法正常工作来索引和搜索位于同一数据源中的两个不同表

San*_*kar 8 xml indexing solr data-import dataimporthandler

我想索引并搜索两个不同的实体.

文件名:db-data-config.xml

<dataConfig>
    <dataSource name="myindex" driver="com.microsoft.sqlserver.jdbc.SQLServerDriver" url="jdbc:sqlserver://test-pc:1433;DatabaseName=SampleDB" user="username" password="password" />
    <document>


     <entity name="Employees" query="select * from employee" transformer="TemplateTransformer" dataSource="myindex">
            <field column="id" name="singlekey" />
            <field column="eId" name="eid" />
            <field column="eName" name="ename" />
            <field column="entity" template="Employee" name="entity" />
    </entity>

    <entity name="Products" query="select * from products" transformer="TemplateTransformer" dataSource="myindex">
            <field column="id" name="singlekey" />
            <field column="pId" name="pid" />
            <field column="pName" name="pname" />
            <field column="entity" template="Product" name="entity" />
    </entity>

</document>
Run Code Online (Sandbox Code Playgroud)

文件名:schema.xml

<?xml version="1.0" encoding="UTF-8" ?>
<schema name="db" version="1.1">
  <types>
    <fieldType name="string" class="solr.StrField" sortMissingLast="true" omitNorms="true"/>
 </types>
 <fields>

    <!-- Employee -->
    <field name="eid" type="string" indexed="true" stored="true" required="true" multiValued="false" /> 
    <field name="ename" type="string" indexed="true" stored="true" required="true" multiValued="false" /> 

    <!-- Products -->
    <field name="pid" type="string" indexed="true" stored="true" required="true" multiValued="false" />
    <field name="pname" type="string" indexed="true" stored="true" required="true" multiValued="false" />

    <!--Common fields-->
    <field name="entity" type="string" indexed="true" stored="true" required="true" multiValued="false" />
    <field name="singlekey" type="string" indexed="true" stored="true" required="true" multiValued="false" />
</fields>
<uniqueKey>singlekey</uniqueKey>
</schema>
Run Code Online (Sandbox Code Playgroud)

如下链接:
https ://stackoverflow.com/questions/5636209/how-to-index-and-search-two-different-tables-which-are-in-same-datasource-using
此问题可以通过使用解决静态字段(添加新字段 - 此处为'实体').但我看到在添加第二个实体后,它甚至无法索引数据.

如下图所示.多个实体问题 - 模板变换器问题

它能够从sql server数据库中获取10条记录,但索引0行,意味着没有完成索引过程.所以即使不能搜索.有谁能解决这个问题?提前致谢.

小智 1

模式中的所有字段都有

required="true".
Run Code Online (Sandbox Code Playgroud)

您告诉 Solr 每个实体的结果需要包含所有 eid、ename、pid、pname、entity 和 singlekey 字段。

Employee doesn't have a pid or pname field, so pid and pname shouldn't be required. In the same sense, Product doesn't have a eid or ename field, so eid and ename shouldn't be required.

Removing

required="true".
Run Code Online (Sandbox Code Playgroud)

from pid, pname, eid, and ename will allow you to index.