Is Solr 4.0 capable of using 'join" for multiple core?

21,749

This comment says it's possible by using:

{!join from=fromField to=toField fromIndex=fromCoreName}fromQuery

I tried it myself, and here's a more detailed example: Have two cores

  • brands {id,name}
  • products {id, name, brand_id}

BRANDS: {1, Apple}, {2, Samsung}, {3, HTC}

PRODUCTS: {1, iPhone, 1}, {2, iPad, 1}, {3, Galaxy S3, 2}, {4, Galaxy Note, 2}, {5, One X, 3}

http://example.com:8999/solr/brands/select?q=*:*&fq={!join from=brand_id to=id fromIndex=products}name:iPad

This translates to something like:

SELECT b.* FROM brands b
       INNER JOIN products p ON b.id=p.brand_id
       WHERE p.name="iPad";

Result will be: {id: "1", name:"Apple"}

Share:
21,749

Related videos on Youtube

zx_wing
Author by

zx_wing

Updated on March 23, 2020

Comments

  • zx_wing
    zx_wing about 4 years

    I notice Solr 4.0 has introduced 'join' feature for documents having relationships. this is great, however, I notice examples given by http://wiki.apache.org/solr/Join are for single core which all documents are in single index.

    Does anybody know if I can use 'join' for multiple core?

  • arun
    arun about 11 years
    Thx for the nice example. More precisely the SQL equivalent is SELECT b.* FROM brands b INNER JOIN products p ON b.id=p.brand_id WHERE p.name="iPad"; since Solr can't give the fields of the fromCore :-(
  • zengr
    zengr almost 11 years
    The query is invalid, it should be: q=name:iPad&fq={!join from=brand_id to=id fromIndex=products} or q=*:*&fq={!join from=brand_id to=id fromIndex=products}name:iPad. q=: is invalid.
  • mjalajel
    mjalajel over 10 years
    @zengr: Yes, the : is displayed as a formatting option, it's fixed now.
  • Adam
    Adam about 3 years
    Is it possible to do something like this if for example the products.id was an array of ids?
  • mjalajel
    mjalajel about 3 years
    @Adam I believe so, yes.