Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

File name: 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>

File name: 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>

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.

As per picture shown below.Multiple entity issue - Template Transformer issue

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.

like image 936
Sanket Thakkar Avatar asked Mar 20 '14 13:03

Sanket Thakkar


1 Answers

All of the fields in your schema have

required="true".

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 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".

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

like image 94
Logue1021 Avatar answered Oct 22 '22 09:10

Logue1021