如何使用单个solr实例或Solr Template字段无法正常工作来索引和搜索位于同一数据源中的两个不同表 [英] 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-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.
如下图所示。
能够获取10条记录来自sql server数据库,但索引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.
推荐答案
架构中的所有字段都
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".
将允许您索引。
这篇关于如何使用单个solr实例或Solr Template字段无法正常工作来索引和搜索位于同一数据源中的两个不同表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!