solrdih

Search in subentity with related fields using Solr and DIH


I want to index and query authors and his bibliography (parent/child relation) using Solr (4.7.2) and DIH from SQLServer DB, and I want to query which authors published a book after 2005, with the title containing the word "wolf", for example.

The configuration files are:

dataimport.xml

<entity name="author" pk="Id" query="SELECT * FROM author"> 
    <field column="Id" name="Id" />
    <field column="name" name="name" />
    <entity name="book" pk=idBook query="SELECT * FROM Book where idAuthor={author.id}">
        <field column="year" name="year" />
        <field column="title" name="title" />
    <entity>
</entity>

schema.xml

<schema name="example" version="1.5">
     <fields>
        <field name="Id" type="int" indexed="true" stored="true" required="true"  />        
        <field name="name" type="text" indexed="true" stored="true" required="false"  />
        <field name="year" type="int" indexed="true" stored="true" required="false"  multiValued="true"/>       
        <field name="title" type="text_en_splitting" indexed="true" stored="true" required="false"  multiValued="true"/>
    </fields>
    [... fieldtypes etc...]
</schema>   

I think with this configuration, I'm loosing the relationship between year and title and shows cross results.

fq=year:[2005 TO *] AND title:wolf

This query returns the authors with minimum one book after 2005 and a book with title with "wolf", but If I want the authors who published a book after 2005 and contains "Wolf".

Thanks in advance


Solution

  • At the end, the best solution is create 2 cores, one with the authors and other with the books. Then you must join the results of the queries, one query to get books with a desired expression, and then search the authors.

    More details at: Is Solr 4.0 capable of using 'join" for multiple core?