Bick
Bick

Reputation: 18541

solr - modeling multiple values on 1:n connection

I try to model my db using this example from solr wiki.

I have a table called item and a table called features with id,featureName,description

here is the updated xml (added featureName)

<dataConfig>
<dataSource driver="org.hsqldb.jdbcDriver" url="jdbc:hsqldb:/temp/example/ex" user="sa" />
<document>
    <entity name="item" query="select * from item">
        <entity name="feature" query="select description, featureName as features from feature where item_id='${item.ID}'"/>
    </entity>
</document>

Now I get two lists in the xml element

<doc>
 <arr name="featureName">
  <str>number of miles in every direction the universal cataclysm  was  gathering</str>
  <str>All around the Restaurant people and things relaxed and chatted.  The</str>
  <str>- Do we have... - he put up a hand to hold back the cheers, -  Do  we</str>
 </arr>
 <arr name="description">
  <str>to a stupefying climax. Glancing at his watch, Max returned to  the  stage</str>
  <str>air was filled with talk of this and that, and with the mingled scents  of</str>
  <str>have a party here from  the  Zansellquasure  Flamarion  Bridge  Club  from</str> 
 </arr>
</doc>

But I would like to see the list together (using xml attributes) so that I dont have to join the values.
Is it possible?

Upvotes: 1

Views: 51

Answers (1)

Ion Cojocaru
Ion Cojocaru

Reputation: 2583

I wanted to suggest the ScriptTransformer, it gives you the flexibility to alter the data as needed, but it will not work in your case since it's working at the row level.

You can always define an aggregation function for string concatenation in SQL(example), but you will potentially have performance issues.

If you would use a http/xml data source the solution would have been to use the flatten atribute.

Nevertheless the search functionality will work as expected even if you ended up with multi-valued fields. The down side would be on the client where you will concatenate them before the presentation layer, which is not really a problem if you use some sort of pagination.

Upvotes: 1

Related Questions