Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

solr JOIN query

Tags:

join

solr

I need to run a JOIN query on a solr index. I've got two xmls that I have indexed, person.xml and subject.xml.

Person:

<doc>
<field name="id">P39126</field>
<field name="family">Smith</field>
<field name="given">John</field>
<field name="subject">S1276</field>
<field name="subject">S1312</field>
</doc>

Subject:

<doc>
<field name="id">S1276</field>
<field name="topic">Abnormalities, Human</field>
</doc>

I need to only display information from the person doc but each query should match fields in both person and subject. In the case the query matches only the subject doc I need to display all docs from the person that have a matching id. Is this possible to do without running two seperate queries? Something like a JOIN query would do the job.

Any help?

like image 300
Sfairas Avatar asked Dec 07 '25 15:12

Sfairas


1 Answers

I do not think it is possible to do what you are asking with a single query using your schema.

One thing that you should keep in mind is to always think of Solr indexes as single denormalized tables. This is sometimes a challenge and there may be times where you must be forced to use different indexes for each kind of data.

For your problem, maybe having a schema like this one might help:

<doc>
 <field name="id">P39126</field>
 <field name="family">Smith</field>
 <field name="given">John</field>
 <field name="topic">Abnormalities, Human</field> <!-- subject S1276 -->
 <field name="topic">some, other, topics</field> <!-- subject S1312 -->
</doc>

Running a query for some topics with this schema would return all person having those topics.

Some links that might interest you:

  • http://www.lucidimagination.com/search/document/93e8b09e90b0076c/help_with_denormalizing_issues#60890dcb99a3004d
  • http://wiki.apache.org/solr/SchemaDesign
like image 168
Pascal Dimassimo Avatar answered Dec 11 '25 06:12

Pascal Dimassimo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!