You are viewing a plain text version of this content. The canonical link for it is here.
Posted to solr-user@lucene.apache.org by Frank He <he...@gmail.com> on 2013/03/08 18:58:36 UTC

how to index multiple table

Hi,
I am now using DHI to import mysql into solr. The data config is like this:

<dataConfig>
  <dataSource type="JdbcDataSource"
              driver="com.mysql.jdbc.Driver"
              url="jdbc:mysql://localhost/accjobs"
              user="root"
              password=""/>
  <document name="jobs">
    <entity name="job" query="select * from job">

           <field column="id" name="id" />
           <field column="title" name="title" />
           <field column="company" name="company" />
           <field column="link" name="link" />
           <field column="snippet" name="snippet" />
           <field column="created_at" name="created_at" />

           <entity name="websource" query="select sourceName from websource
where id= '${job.websource_id}'">
               <field column="sourceName" name="sourceName" />
           </entity>

           <entity name="city" query="select name from city where id=
'${job.city_id}'">
               <field column="name" name="city" />
               <entity name="country" query="select shortname from country
where id= '${city.country_id}'">
                       <field column="shortname" name="countryName" />
               </entity>
           </entity>


    </entity>
  </document>
</dataConfig>

and schema is:

<field name="id" type="int" indexed="true" stored="true" required="true"
multiValued="false" />
   <field name="title" type="string" indexed="true" stored="true"/>
   <field name="company" type="string" indexed="true" stored="true"/>
   <field name="link" type="string" indexed="false" stored="true"/>
   <field name="snippet" type="text_general" indexed="true" stored="true"/>
   <field name="created_at" type="date" indexed="true" stored="true"/>
   <field name="sourceName" type="string" indexed="true" stored="true"/>

   <field name="city" type="string" indexed="true" stored="true"/>
   <field name="countryName" type="string" indexed="true" stored="true"/>


But after I run full-commit, everything is fine except the countryName is
missing.

Can anyone tell me what is wrong with this?

Re: how to index multiple table

Posted by Alexandre Rafalovitch <ar...@gmail.com>.
Where does your '${city.country_id} coming from? You need to select it. You
may also need to define a 'field' for it, so the VariableResolver notices
it. That field can be only in DIH and be dropped when it matches schema. In
fact, you don't even need 'name' attribute, just 'column' one:
So:
1) <entity name="city" query="select name, country_id from city where id=
'${job.city_id}'">
2) <field column='country_id'/>

Regards,
   Alex.