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

标签 xml solr indexing dataimporthandler data-import

我想索引和搜索两个不同的实体。

文件名: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>

文件名: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>

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

如下图所示。 Multiple entity issue - Template Transformer issue

它能够从 sql server 数据库获取 10 条记录,但索引 0 行,这意味着没有完成索引过程。 所以连搜索都搜不到。 任何人都可以解决这个问题吗? 提前致谢。

最佳答案

架构中的所有字段都有

required="true".

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

Employee 没有 pid 或 pname 字段,因此不应要求提供 pid 和 pname。同样,Product 没有 eid 或 ename 字段,因此不应要求提供 eid 和 ename。

删除

required="true".

pid、pname、eid 和 ename 将允许您建立索引。

关于xml - 如何使用单个 solr 实例或 Solr 模板字段无法正常工作来索引和搜索同一数据源中的两个不同表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22534121/

相关文章:

jQuery 整体元素索引

python - 使用 ElementTree 删除父标签(不删除子标签)

xml - 如何在PowerShell中自动创建XML的新元素?

Azure 应用服务 - 在 Jetty 上运行 Solr - Azure 维护后发生 LockObtainFailedException

Solr:如何提高数字字段上的过滤器查询(针对特定值,而不是范围查询)的性能?

android - TextView 中字符串中的 OnClick 位置

xml - 使用VB.Net解析复杂的xml : elements into strings depending on namespace

java - 更改默认布局时应用程序崩溃说,不幸的是应用程序已停止

python - django haystack 没有索引

sql - 查询不进行索引查找或扫描