user1731299
user1731299

Reputation: 567

Solr - problems with compound Id

For example I have 2 tables: table1 = book, table2 = site --> 1 book can have n sites.

<entity name="book" dataSource="myDs" pk="id"
        transformer="TemplateTransformer"
        query="SELECT b.id, b.title, s.id, s.number, s.content
                     FROM book b. site s WHERE b.id = s.book">
        <field column="b.id" name="id" />
        <field column="s.id" name="sId" />
        <field column="id" template="${id}_${sId}" ignoreMissingVariables="true" />
    </entity>

Why this dont work? I just get only 1 book with 1 site as result and not x book with x sites I just dont get a compound key in field 'id'.

Upvotes: 1

Views: 425

Answers (3)

ajayb
ajayb

Reputation: 21

I recently ran into similar issue and following points fixed it for me:

  1. In SQL query use alias to get distinct column names. Please recheck the sytax of alias as it may vary for your database.
  2. when you use template transformer or do sub select (on inner entities), always use entity.COLUMN_NAME_IN_CAPITAL. The column-in-capital really stumped me until I stumbled upond solr forum where someone else suggested that as a solution (unfortunately I do not have the URL of the post that provided this helpful tidbit).

i was doing above against Oracle DB. Not 100% sure if it applies to other DB but wanted to share the solution.

Here is an attempt to re define your DIH with the above changes

<entity name="book" dataSource="myDs" pk="id"
    transformer="TemplateTransformer"
    query="SELECT b.id, b.title, s.id as sid, s.number, s.content
                 FROM book b. site s WHERE b.id = s.book">
    <field column="sid" name="sid" />
    <field column="id" template="${book.ID}_${book.SID}"/>
</entity>

Upvotes: 2

user1731299
user1731299

Reputation: 567

yes I deleted the index and inserted him new.

what I get:

   <doc>
    <str name="id">1</str>
    <str name="title">Im a title</str>
    <str name="number">1337</str>
   <str name="content">content 23</str>
  </doc>

what I want:

   <doc>
    <str name="id">1_1</str>
    <str name="title">Im a title</str>
    <str name="number">1337</str>
   <str name="content">content 23</str>
  </doc>

   <doc>
    <str name="id">1_2</str>
    <str name="title">Im a title for 2</str>
    <str name="number">1654654</str>
   <str name="content">ekddsd</str>
  </doc>

I already tried to change following

<field column="id" template="${id}_${sId}" ignoreMissingVariables="true" />

into

<field column="id" template="${id}_${someOtherField}" ignoreMissingVariables="true" />

and the result didn't change.. Looks like the TemplateTransformer doesn't work?

EDIT Found something in my logs:

Unable to resolve variable: id while parsing expression: ${id}_${sId}
Unable to resolve variable: sId while parsing expression: ${id}_${sId}

Upvotes: 0

Parvin Gasimzade
Parvin Gasimzade

Reputation: 26032

Add multivalued=true to the id and sId fields in schema.xml file.

Upvotes: 0

Related Questions