如何使用单个 solr 实例或 Solr 模板字段无法正常工作来索引和搜索同一数据源中的两个不同表 [英] How to index and search two different tables which are in same datasource using single solr instance Or Solr Template fields not working properly
问题描述
我想索引和搜索两个不同的实体.
I want to index and search two different entity.
文件名: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').但是我看到添加第二个实体后,它甚至无法索引数据.
As per below link:
https://stackoverflow.com/questions/5636209/how-to-index-and-search-two-different-tables-which-are-in-same-datasource-using
This problem can solve by using static field (adding new field - here its 'entity').
But I saw that after adding second entity, it can't even index the data.
如下图所示.
它能够从 sql server 数据库中获取 10 条记录,但是索引 0 行,这意味着没有完成索引过程.所以连搜索都搜不到.任何人都可以解决这个问题?提前致谢.
Its able to fetch 10 records from sql server database but index 0 rows, means no indexing process done. So even can't search. Anyone can solve this problem? Thanks in advance.
推荐答案
架构中的所有字段都有
All of the fields in your schema have
required="true".
您告诉 Solr 每个实体的结果需要包含所有 eid、ename、pid、pname、entity 和 singlekey 字段.
You're telling Solr that the results from each entity need to have ALL of the eid, ename, pid, pname, entity, and singlekey fields.
Employee 没有 pid 或 pname 字段,因此不需要 pid 和 pname.同样,Product 没有 eid 或 ename 字段,因此不需要 eid 和 ename.
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.
删除
required="true".
来自 pid、pname、eid 和 ename 将允许您建立索引.
from pid, pname, eid, and ename will allow you to index.
这篇关于如何使用单个 solr 实例或 Solr 模板字段无法正常工作来索引和搜索同一数据源中的两个不同表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!