You are viewing a plain text version of this content. The canonical link for it is here.
Posted to solr-user@lucene.apache.org by Tech Id <te...@gmail.com> on 2013/11/05 18:31:44 UTC

Example of join using Solr/Lucene

Hi,

I have been searching for an example of joins using solr/lucene.
But I have not found anything either on the net or in the src/examples.

Can someone please point me to the same?
Ideally, I need a join working with Solrj APIs (Please let me know if this
group is Lucene-specific).


Best Regards

Re: Example of join using Solr/Lucene

Posted by Alvaro Cabrerizo <to...@gmail.com>.
You can also go further and ask:

Give me all the people that drive a toyota (company->car->people):

*q=*:*&fq=*:* AND _query_:"{!join to=id from=ownerId}id:* AND
_query_:{!join to=companyId from=id}name:toyo*"*

If we divide this query in fragments we got:


   - *q=*:**  which is restriction over people, so you can add here every
   constraint you can imagine about people.


In the other side fq can be divided in two parts:


   - *id:* AND _query_:{!join to=companyId from=id}name:toyo**  which
   extracts all the cars that satisfy nothing ("id:*") and  which companiId
   points to a company with a name that starts with "toyo" (AND _query_:{!join
   to=companyId from=id}name:toyo*)
   - *{!join to=id from=ownerId}* Use the former list of cars to make a
   join with the documents pointed by ownedId (i.e. people).


Regards.



On Wed, Nov 6, 2013 at 9:43 PM, Alvaro Cabrerizo <to...@gmail.com> wrote:

> For example, a dummy schema (if we index the former data in separate
> documents) should look like this:
>
> ...
>                 <field name="color" type="string" indexed="true"
> stored="true" />
>                 <field name="year" type="int" indexed="true" stored="true"
> />
>                 <field name="companyId" type="string" indexed="true"
> stored="true" />
>                 <field name="ownerId" type="string" indexed="true"
> stored="true" />
>                 <field name="name" type="text" indexed="true"
> stored="true" />
>                 <field name="numEmployees" type="int" indexed="true"
> stored="true" />
>                 <field name="established" type="int" indexed="true"
> stored="true" />
>                 <field name="age" type="text"  indexed="true"
> stored="true" />
>                 <field name="profession" type="text" indexed="true"
> stored="true" />
>                 <field name="spouseId" type="string" indexed="true"
> stored="true" />
>                 <field name="carOwnedId" type="string" indexed="true"
> stored="true" />
> ...
>
> So as you can see the schema.xml has no information about foreign keys.
>
> With this schema we can answer:
>
> - Give me all the cars done by toyota:
>
> q=id:*&fq={!join%20to=companyId%20from=id}id:23
>
> q=id:*&fq={!join%20to=companyId%20from=id}name:toyo*%20AND%20id:2*
>
> As you can imagine q gives me all the documents and later I filter them
> saying just to return those which companyId has a company tha
> t satisfies id=23 or in the second example its name start by toyo and its
> id starts by 2.
>
> Regards.
>
>
> On Wed, Nov 6, 2013 at 7:55 PM, Alvaro Cabrerizo <to...@gmail.com>wrote:
>
>> You  can check these links:
>>
>> http://wiki.apache.org/solr/Join
>>
>>
>> http://stackoverflow.com/questions/12665797/is-solr-4-0-capable-of-using-join-for-multiple-core
>>
>> Regards.
>>
>>
>> On Wed, Nov 6, 2013 at 1:00 AM, Tech Id <te...@gmail.com> wrote:
>>
>>> Hi Alvaro,
>>>
>>> Could you please point me to some link from where I can see how to index
>>> two documents separately (joined by foreign keys).
>>> Or if you can oblige by putting down some details here itself.
>>>
>>> *For example*, say if user has entities like :
>>>   car  {id:5, color:red, year:2004, companyId:23, ownerId: 57},
>>>   company {id:23, name: toyota, numEmployees:1000, established:1980},
>>>   owner {id: 57, name: John, age: 50, profession: doctor, spouseId: 78,
>>> carOwnedId: 5},
>>>   owner {id: 78, name: Maria, age: 45, profession: doctor, spouseId: 57,
>>> carOwnedId: 55}
>>>   etc.
>>> 1) How can the above entities be put into Solr with their foreign keys?
>>> 2) Do we need to flatten them absolutely?
>>> 3) How are cyclic joins handled in flattening?
>>>
>>> Some good link on how a join query can be actually run would also be
>>> appreciated.
>>> (I have some links on the reading part, but a complete example would be
>>> good).
>>>
>>> Thanks
>>>
>>>
>>>
>>> On Tue, Nov 5, 2013 at 10:53 AM, Alvaro Cabrerizo <toporniz@gmail.com
>>> >wrote:
>>>
>>> > In my case, everytime I've used joins, the FROM field was a multivalued
>>> > string and the TO was an univalued string.
>>> >
>>> > Regards.
>>> > El 05/11/2013 18:37, "Tech Id" <te...@gmail.com> escribió:
>>> >
>>> > > I think Solr has the ability to do joins in the latest version as
>>> > verified
>>> > > on this issue: https://issues.apache.org/jira/browse/SOLR-3076
>>> > >
>>> > > And some online resources point to this example:
>>> > >
>>> > >
>>> >
>>> http://blog.mikemccandless.com/2012/01/searching-relational-content-with.html
>>> > > However, I am not sure if the above example is a complete one.
>>> > > It leaves a lot for a fresh solr-user to guess about how to
>>> customize the
>>> > > schema and how to index two documents into Solr before doing a join.
>>> > >
>>> > >
>>> > >
>>> > > On Tue, Nov 5, 2013 at 9:31 AM, Tech Id <te...@gmail.com>
>>> > wrote:
>>> > >
>>> > > > Hi,
>>> > > >
>>> > > > I have been searching for an example of joins using solr/lucene.
>>> > > > But I have not found anything either on the net or in the
>>> src/examples.
>>> > > >
>>> > > > Can someone please point me to the same?
>>> > > > Ideally, I need a join working with Solrj APIs (Please let me know
>>> if
>>> > > this
>>> > > > group is Lucene-specific).
>>> > > >
>>> > > >
>>> > > > Best Regards
>>> > > >
>>> > > >
>>> > >
>>> >
>>>
>>
>>
>

Re: Example of join using Solr/Lucene

Posted by Alvaro Cabrerizo <to...@gmail.com>.
For example, a dummy schema (if we index the former data in separate
documents) should look like this:

...
                <field name="color" type="string" indexed="true"
stored="true" />
                <field name="year" type="int" indexed="true" stored="true"
/>
                <field name="companyId" type="string" indexed="true"
stored="true" />
                <field name="ownerId" type="string" indexed="true"
stored="true" />
                <field name="name" type="text" indexed="true" stored="true"
/>
                <field name="numEmployees" type="int" indexed="true"
stored="true" />
                <field name="established" type="int" indexed="true"
stored="true" />
                <field name="age" type="text"  indexed="true" stored="true"
/>
                <field name="profession" type="text" indexed="true"
stored="true" />
                <field name="spouseId" type="string" indexed="true"
stored="true" />
                <field name="carOwnedId" type="string" indexed="true"
stored="true" />
...

So as you can see the schema.xml has no information about foreign keys.

With this schema we can answer:

- Give me all the cars done by toyota:

q=id:*&fq={!join%20to=companyId%20from=id}id:23

q=id:*&fq={!join%20to=companyId%20from=id}name:toyo*%20AND%20id:2*

As you can imagine q gives me all the documents and later I filter them
saying just to return those which companyId has a company tha
t satisfies id=23 or in the second example its name start by toyo and its
id starts by 2.

Regards.


On Wed, Nov 6, 2013 at 7:55 PM, Alvaro Cabrerizo <to...@gmail.com> wrote:

> You  can check these links:
>
> http://wiki.apache.org/solr/Join
>
>
> http://stackoverflow.com/questions/12665797/is-solr-4-0-capable-of-using-join-for-multiple-core
>
> Regards.
>
>
> On Wed, Nov 6, 2013 at 1:00 AM, Tech Id <te...@gmail.com> wrote:
>
>> Hi Alvaro,
>>
>> Could you please point me to some link from where I can see how to index
>> two documents separately (joined by foreign keys).
>> Or if you can oblige by putting down some details here itself.
>>
>> *For example*, say if user has entities like :
>>   car  {id:5, color:red, year:2004, companyId:23, ownerId: 57},
>>   company {id:23, name: toyota, numEmployees:1000, established:1980},
>>   owner {id: 57, name: John, age: 50, profession: doctor, spouseId: 78,
>> carOwnedId: 5},
>>   owner {id: 78, name: Maria, age: 45, profession: doctor, spouseId: 57,
>> carOwnedId: 55}
>>   etc.
>> 1) How can the above entities be put into Solr with their foreign keys?
>> 2) Do we need to flatten them absolutely?
>> 3) How are cyclic joins handled in flattening?
>>
>> Some good link on how a join query can be actually run would also be
>> appreciated.
>> (I have some links on the reading part, but a complete example would be
>> good).
>>
>> Thanks
>>
>>
>>
>> On Tue, Nov 5, 2013 at 10:53 AM, Alvaro Cabrerizo <toporniz@gmail.com
>> >wrote:
>>
>> > In my case, everytime I've used joins, the FROM field was a multivalued
>> > string and the TO was an univalued string.
>> >
>> > Regards.
>> > El 05/11/2013 18:37, "Tech Id" <te...@gmail.com> escribió:
>> >
>> > > I think Solr has the ability to do joins in the latest version as
>> > verified
>> > > on this issue: https://issues.apache.org/jira/browse/SOLR-3076
>> > >
>> > > And some online resources point to this example:
>> > >
>> > >
>> >
>> http://blog.mikemccandless.com/2012/01/searching-relational-content-with.html
>> > > However, I am not sure if the above example is a complete one.
>> > > It leaves a lot for a fresh solr-user to guess about how to customize
>> the
>> > > schema and how to index two documents into Solr before doing a join.
>> > >
>> > >
>> > >
>> > > On Tue, Nov 5, 2013 at 9:31 AM, Tech Id <te...@gmail.com>
>> > wrote:
>> > >
>> > > > Hi,
>> > > >
>> > > > I have been searching for an example of joins using solr/lucene.
>> > > > But I have not found anything either on the net or in the
>> src/examples.
>> > > >
>> > > > Can someone please point me to the same?
>> > > > Ideally, I need a join working with Solrj APIs (Please let me know
>> if
>> > > this
>> > > > group is Lucene-specific).
>> > > >
>> > > >
>> > > > Best Regards
>> > > >
>> > > >
>> > >
>> >
>>
>
>

Re: Example of join using Solr/Lucene

Posted by Alvaro Cabrerizo <to...@gmail.com>.
You  can check these links:

http://wiki.apache.org/solr/Join

http://stackoverflow.com/questions/12665797/is-solr-4-0-capable-of-using-join-for-multiple-core

Regards.


On Wed, Nov 6, 2013 at 1:00 AM, Tech Id <te...@gmail.com> wrote:

> Hi Alvaro,
>
> Could you please point me to some link from where I can see how to index
> two documents separately (joined by foreign keys).
> Or if you can oblige by putting down some details here itself.
>
> *For example*, say if user has entities like :
>   car  {id:5, color:red, year:2004, companyId:23, ownerId: 57},
>   company {id:23, name: toyota, numEmployees:1000, established:1980},
>   owner {id: 57, name: John, age: 50, profession: doctor, spouseId: 78,
> carOwnedId: 5},
>   owner {id: 78, name: Maria, age: 45, profession: doctor, spouseId: 57,
> carOwnedId: 55}
>   etc.
> 1) How can the above entities be put into Solr with their foreign keys?
> 2) Do we need to flatten them absolutely?
> 3) How are cyclic joins handled in flattening?
>
> Some good link on how a join query can be actually run would also be
> appreciated.
> (I have some links on the reading part, but a complete example would be
> good).
>
> Thanks
>
>
>
> On Tue, Nov 5, 2013 at 10:53 AM, Alvaro Cabrerizo <toporniz@gmail.com
> >wrote:
>
> > In my case, everytime I've used joins, the FROM field was a multivalued
> > string and the TO was an univalued string.
> >
> > Regards.
> > El 05/11/2013 18:37, "Tech Id" <te...@gmail.com> escribió:
> >
> > > I think Solr has the ability to do joins in the latest version as
> > verified
> > > on this issue: https://issues.apache.org/jira/browse/SOLR-3076
> > >
> > > And some online resources point to this example:
> > >
> > >
> >
> http://blog.mikemccandless.com/2012/01/searching-relational-content-with.html
> > > However, I am not sure if the above example is a complete one.
> > > It leaves a lot for a fresh solr-user to guess about how to customize
> the
> > > schema and how to index two documents into Solr before doing a join.
> > >
> > >
> > >
> > > On Tue, Nov 5, 2013 at 9:31 AM, Tech Id <te...@gmail.com>
> > wrote:
> > >
> > > > Hi,
> > > >
> > > > I have been searching for an example of joins using solr/lucene.
> > > > But I have not found anything either on the net or in the
> src/examples.
> > > >
> > > > Can someone please point me to the same?
> > > > Ideally, I need a join working with Solrj APIs (Please let me know if
> > > this
> > > > group is Lucene-specific).
> > > >
> > > >
> > > > Best Regards
> > > >
> > > >
> > >
> >
>

Re: Example of join using Solr/Lucene

Posted by Tech Id <te...@gmail.com>.
Hi Alvaro,

Could you please point me to some link from where I can see how to index
two documents separately (joined by foreign keys).
Or if you can oblige by putting down some details here itself.

*For example*, say if user has entities like :
  car  {id:5, color:red, year:2004, companyId:23, ownerId: 57},
  company {id:23, name: toyota, numEmployees:1000, established:1980},
  owner {id: 57, name: John, age: 50, profession: doctor, spouseId: 78,
carOwnedId: 5},
  owner {id: 78, name: Maria, age: 45, profession: doctor, spouseId: 57,
carOwnedId: 55}
  etc.
1) How can the above entities be put into Solr with their foreign keys?
2) Do we need to flatten them absolutely?
3) How are cyclic joins handled in flattening?

Some good link on how a join query can be actually run would also be
appreciated.
(I have some links on the reading part, but a complete example would be
good).

Thanks



On Tue, Nov 5, 2013 at 10:53 AM, Alvaro Cabrerizo <to...@gmail.com>wrote:

> In my case, everytime I've used joins, the FROM field was a multivalued
> string and the TO was an univalued string.
>
> Regards.
> El 05/11/2013 18:37, "Tech Id" <te...@gmail.com> escribió:
>
> > I think Solr has the ability to do joins in the latest version as
> verified
> > on this issue: https://issues.apache.org/jira/browse/SOLR-3076
> >
> > And some online resources point to this example:
> >
> >
> http://blog.mikemccandless.com/2012/01/searching-relational-content-with.html
> > However, I am not sure if the above example is a complete one.
> > It leaves a lot for a fresh solr-user to guess about how to customize the
> > schema and how to index two documents into Solr before doing a join.
> >
> >
> >
> > On Tue, Nov 5, 2013 at 9:31 AM, Tech Id <te...@gmail.com>
> wrote:
> >
> > > Hi,
> > >
> > > I have been searching for an example of joins using solr/lucene.
> > > But I have not found anything either on the net or in the src/examples.
> > >
> > > Can someone please point me to the same?
> > > Ideally, I need a join working with Solrj APIs (Please let me know if
> > this
> > > group is Lucene-specific).
> > >
> > >
> > > Best Regards
> > >
> > >
> >
>

Re: Example of join using Solr/Lucene

Posted by Alvaro Cabrerizo <to...@gmail.com>.
In my case, everytime I've used joins, the FROM field was a multivalued
string and the TO was an univalued string.

Regards.
El 05/11/2013 18:37, "Tech Id" <te...@gmail.com> escribió:

> I think Solr has the ability to do joins in the latest version as verified
> on this issue: https://issues.apache.org/jira/browse/SOLR-3076
>
> And some online resources point to this example:
>
> http://blog.mikemccandless.com/2012/01/searching-relational-content-with.html
> However, I am not sure if the above example is a complete one.
> It leaves a lot for a fresh solr-user to guess about how to customize the
> schema and how to index two documents into Solr before doing a join.
>
>
>
> On Tue, Nov 5, 2013 at 9:31 AM, Tech Id <te...@gmail.com> wrote:
>
> > Hi,
> >
> > I have been searching for an example of joins using solr/lucene.
> > But I have not found anything either on the net or in the src/examples.
> >
> > Can someone please point me to the same?
> > Ideally, I need a join working with Solrj APIs (Please let me know if
> this
> > group is Lucene-specific).
> >
> >
> > Best Regards
> >
> >
>

Re: Example of join using Solr/Lucene

Posted by Tech Id <te...@gmail.com>.
I think Solr has the ability to do joins in the latest version as verified
on this issue: https://issues.apache.org/jira/browse/SOLR-3076

And some online resources point to this example:
http://blog.mikemccandless.com/2012/01/searching-relational-content-with.html
However, I am not sure if the above example is a complete one.
It leaves a lot for a fresh solr-user to guess about how to customize the
schema and how to index two documents into Solr before doing a join.



On Tue, Nov 5, 2013 at 9:31 AM, Tech Id <te...@gmail.com> wrote:

> Hi,
>
> I have been searching for an example of joins using solr/lucene.
> But I have not found anything either on the net or in the src/examples.
>
> Can someone please point me to the same?
> Ideally, I need a join working with Solrj APIs (Please let me know if this
> group is Lucene-specific).
>
>
> Best Regards
>
>