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 Avlesh Singh <av...@gmail.com> on 2009/11/01 05:30:04 UTC

Re: Indexing multiple entities

>
> The use case on DocumentObjectBinder is that I could override
> toSolrInputDocument, and if field = ID, I could do: setField("id",
> obj.getClass().getName() + obj.getId()) or something like that.
>

Unless I am missing something here, can't you write the getter of id field
in your solr bean as underneath?

@Field
private String id;
public getId(){
  return (this.getClass().getName() + this.id);
}

Cheers
Avlesh

On Fri, Oct 30, 2009 at 1:33 PM, Christian López Espínola <
penyaskito@gmail.com> wrote:

> On Fri, Oct 30, 2009 at 2:04 AM, Avlesh Singh <av...@gmail.com> wrote:
> >>
> >> One thing I thought about is if I can define my own
> >> DocumentObjectBinder, so I can concatenate my entity names with the
> >> IDs in the XML creation.
> >>
> >> Anyone knows if something like this can be done without modifying
> >> Solrj sources? Is there any injection or plugin mecanism for this?
> >>
> > More details on the use-case please.
>
> If I index a Book with ID=3, and then a Magazine with ID=3, I'll be
> really removing my Book3 and indexing Magazine3. I want both entities
> to be in the index.
>
> The use case on DocumentObjectBinder is that I could override
> toSolrInputDocument, and if field = ID, I could do: setField("id",
> obj.getClass().getName() + obj.getId()) or something like that.
>
> The goal is avoiding creating all the XMLs to be sent to Solr but
> having the possibility of modifying them in some way.
>
> Do you know how can I do that, or a better way of achieving the same
> results?
>
>
> > Cheers
> > Avlesh
> >
> > On Fri, Oct 30, 2009 at 2:16 AM, Christian López Espínola <
> > penyaskito@gmail.com> wrote:
> >
> >> Hi Israel,
> >>
> >> Thanks for your suggestion,
> >>
> >> On Thu, Oct 29, 2009 at 9:37 PM, Israel Ekpo <is...@gmail.com>
> wrote:
> >> > On Thu, Oct 29, 2009 at 3:31 PM, Christian López Espínola <
> >> > penyaskito@gmail.com> wrote:
> >> >
> >> >> Hi, my name is Christian and I'm a newbie introducing to solr (and
> >> solrj).
> >> >>
> >> >> I'm working on a website where I want to index multiple entities,
> like
> >> >> Book or Magazine.
> >> >> The issue I'm facing is both of them have an attribute ID, which I
> >> >> want to use as the uniqueKey on my schema, so I cannot identify
> >> >> uniquely a document (because ID is saved in a database too, and it's
> >> >> autonumeric).
> >> >>
> >> >> I'm sure that this is a common pattern, but I don't find the way of
> >> solving
> >> >> it.
> >> >>
> >> >> How do you usually solve this? Thanks in advance.
> >> >>
> >> >>
> >> >> --
> >> >> Cheers,
> >> >>
> >> >> Christian López Espínola <penyaskito>
> >> >>
> >> >
> >> > Hi Christian,
> >> >
> >> > It looks like you are bringing in data to Solr from a database where
> >> there
> >> > are two separate tables.
> >> >
> >> > One for *Books* and another one for *Magazines*.
> >> >
> >> > If this is the case, you could define your uniqueKey element in Solr
> >> schema
> >> > to be a "string" instead of an integer then you can still load
> documents
> >> > from both the books and magazines database tables but your could
> prefix
> >> the
> >> > uniqueKey field with "B" for books and "M" for magazines
> >> >
> >> > Like so :
> >> >
> >> > <field name="id" type="string" indexed="true" stored="true"
> >> > required="true"/>
> >> >
> >> > <uniqueKey>id</uniqueKey>
> >> >
> >> > Then when loading the books or magazines into Solr you can create the
> >> > documents with id fields like this
> >> >
> >> > <add>
> >> >  <doc>
> >> >    <field name="id">B14000</field>
> >> >  </doc>
> >> >  <doc>
> >> >    <field name="id">M14000</field>
> >> >  </doc>
> >> >  <doc>
> >> >    <field name="id">B14001</field>
> >> >  </doc>
> >> >  <doc>
> >> >    <field name="id">M14001</field>
> >> >  </doc>
> >> > </add>
> >> >
> >> > I hope this helps
> >>
> >> This was my first thought, but in practice there isn't Book and
> >> Magazine, but about 50 different entities, so I'm using the Field
> >> annotation of solrj for simplifying my code (it manages for me the XML
> >> creation, etc).
> >> One thing I thought about is if I can define my own
> >> DocumentObjectBinder, so I can concatenate my entity names with the
> >> IDs in the XML creation.
> >>
> >> Anyone knows if something like this can be done without modifying
> >> Solrj sources? Is there any injection or plugin mecanism for this?
> >>
> >> Thanks in advance.
> >>
> >>
> >> > --
> >> > "Good Enough" is not good enough.
> >> > To give anything less than your best is to sacrifice the gift.
> >> > Quality First. Measure Twice. Cut Once.
> >> >
> >>
> >>
> >>
> >> --
> >> Cheers,
> >>
> >> Christian López Espínola <penyaskito>
> >>
> >
>
>
>
> --
> Cheers,
>
> Christian López Espínola <penyaskito>
>

Re: Indexing multiple entities

Posted by Christian López Espínola <pe...@gmail.com>.
On Sun, Nov 1, 2009 at 10:34 AM, Christian López Espínola
<pe...@gmail.com> wrote:
> On Sun, Nov 1, 2009 at 5:30 AM, Avlesh Singh <av...@gmail.com> wrote:
>>>
>>> The use case on DocumentObjectBinder is that I could override
>>> toSolrInputDocument, and if field = ID, I could do: setField("id",
>>> obj.getClass().getName() + obj.getId()) or something like that.
>>>
>>
>> Unless I am missing something here, can't you write the getter of id field
>> in your solr bean as underneath?
>>
>> @Field
>> private String id;
>> public getId(){
>>  return (this.getClass().getName() + this.id);
>> }
>
> I'm using a code generator for my entities, and I cannot modify the generation.
> I need to work out another option :(

Finally, I've been able of modifying my code generation scripts
without any side effects.
Thanks everyone for the suggestions.

>> Cheers
>> Avlesh
>>
>> On Fri, Oct 30, 2009 at 1:33 PM, Christian López Espínola <
>> penyaskito@gmail.com> wrote:
>>
>>> On Fri, Oct 30, 2009 at 2:04 AM, Avlesh Singh <av...@gmail.com> wrote:
>>> >>
>>> >> One thing I thought about is if I can define my own
>>> >> DocumentObjectBinder, so I can concatenate my entity names with the
>>> >> IDs in the XML creation.
>>> >>
>>> >> Anyone knows if something like this can be done without modifying
>>> >> Solrj sources? Is there any injection or plugin mecanism for this?
>>> >>
>>> > More details on the use-case please.
>>>
>>> If I index a Book with ID=3, and then a Magazine with ID=3, I'll be
>>> really removing my Book3 and indexing Magazine3. I want both entities
>>> to be in the index.
>>>
>>> The use case on DocumentObjectBinder is that I could override
>>> toSolrInputDocument, and if field = ID, I could do: setField("id",
>>> obj.getClass().getName() + obj.getId()) or something like that.
>>>
>>> The goal is avoiding creating all the XMLs to be sent to Solr but
>>> having the possibility of modifying them in some way.
>>>
>>> Do you know how can I do that, or a better way of achieving the same
>>> results?
>>>
>>>
>>> > Cheers
>>> > Avlesh
>>> >
>>> > On Fri, Oct 30, 2009 at 2:16 AM, Christian López Espínola <
>>> > penyaskito@gmail.com> wrote:
>>> >
>>> >> Hi Israel,
>>> >>
>>> >> Thanks for your suggestion,
>>> >>
>>> >> On Thu, Oct 29, 2009 at 9:37 PM, Israel Ekpo <is...@gmail.com>
>>> wrote:
>>> >> > On Thu, Oct 29, 2009 at 3:31 PM, Christian López Espínola <
>>> >> > penyaskito@gmail.com> wrote:
>>> >> >
>>> >> >> Hi, my name is Christian and I'm a newbie introducing to solr (and
>>> >> solrj).
>>> >> >>
>>> >> >> I'm working on a website where I want to index multiple entities,
>>> like
>>> >> >> Book or Magazine.
>>> >> >> The issue I'm facing is both of them have an attribute ID, which I
>>> >> >> want to use as the uniqueKey on my schema, so I cannot identify
>>> >> >> uniquely a document (because ID is saved in a database too, and it's
>>> >> >> autonumeric).
>>> >> >>
>>> >> >> I'm sure that this is a common pattern, but I don't find the way of
>>> >> solving
>>> >> >> it.
>>> >> >>
>>> >> >> How do you usually solve this? Thanks in advance.
>>> >> >>
>>> >> >>
>>> >> >> --
>>> >> >> Cheers,
>>> >> >>
>>> >> >> Christian López Espínola <penyaskito>
>>> >> >>
>>> >> >
>>> >> > Hi Christian,
>>> >> >
>>> >> > It looks like you are bringing in data to Solr from a database where
>>> >> there
>>> >> > are two separate tables.
>>> >> >
>>> >> > One for *Books* and another one for *Magazines*.
>>> >> >
>>> >> > If this is the case, you could define your uniqueKey element in Solr
>>> >> schema
>>> >> > to be a "string" instead of an integer then you can still load
>>> documents
>>> >> > from both the books and magazines database tables but your could
>>> prefix
>>> >> the
>>> >> > uniqueKey field with "B" for books and "M" for magazines
>>> >> >
>>> >> > Like so :
>>> >> >
>>> >> > <field name="id" type="string" indexed="true" stored="true"
>>> >> > required="true"/>
>>> >> >
>>> >> > <uniqueKey>id</uniqueKey>
>>> >> >
>>> >> > Then when loading the books or magazines into Solr you can create the
>>> >> > documents with id fields like this
>>> >> >
>>> >> > <add>
>>> >> >  <doc>
>>> >> >    <field name="id">B14000</field>
>>> >> >  </doc>
>>> >> >  <doc>
>>> >> >    <field name="id">M14000</field>
>>> >> >  </doc>
>>> >> >  <doc>
>>> >> >    <field name="id">B14001</field>
>>> >> >  </doc>
>>> >> >  <doc>
>>> >> >    <field name="id">M14001</field>
>>> >> >  </doc>
>>> >> > </add>
>>> >> >
>>> >> > I hope this helps
>>> >>
>>> >> This was my first thought, but in practice there isn't Book and
>>> >> Magazine, but about 50 different entities, so I'm using the Field
>>> >> annotation of solrj for simplifying my code (it manages for me the XML
>>> >> creation, etc).
>>> >> One thing I thought about is if I can define my own
>>> >> DocumentObjectBinder, so I can concatenate my entity names with the
>>> >> IDs in the XML creation.
>>> >>
>>> >> Anyone knows if something like this can be done without modifying
>>> >> Solrj sources? Is there any injection or plugin mecanism for this?
>>> >>
>>> >> Thanks in advance.
>>> >>
>>> >>
>>> >> > --
>>> >> > "Good Enough" is not good enough.
>>> >> > To give anything less than your best is to sacrifice the gift.
>>> >> > Quality First. Measure Twice. Cut Once.
>>> >> >
>>> >>
>>> >>
>>> >>
>>> >> --
>>> >> Cheers,
>>> >>
>>> >> Christian López Espínola <penyaskito>
>>> >>
>>> >
>>>
>>>
>>>
>>> --
>>> Cheers,
>>>
>>> Christian López Espínola <penyaskito>
>>>
>>
>
>
>
> --
> Cheers,
>
> Christian López Espínola <penyaskito>
>



-- 
Cheers,

Christian López Espínola <penyaskito>

Re: Indexing multiple entities

Posted by Christian López Espínola <pe...@gmail.com>.
On Mon, Nov 2, 2009 at 11:07 AM, Chantal Ackermann
<ch...@btelligent.de> wrote:
>> I'm using a code generator for my entities, and I cannot modify the
>> generation.
>> I need to work out another option :(
>
> shouldn't code generators help development and not make it more complex and
> difficult? oO

Yeah, they do. But I wasn't clever enough for solving this until today ;-)

> (sry off topic)
>
> chantal
>



-- 
Cheers,

Christian López Espínola <penyaskito>

Re: Indexing multiple entities

Posted by Chantal Ackermann <ch...@btelligent.de>.
> I'm using a code generator for my entities, and I cannot modify the generation.
> I need to work out another option :(

shouldn't code generators help development and not make it more complex 
and difficult? oO

(sry off topic)

chantal

Re: Indexing multiple entities

Posted by Christian López Espínola <pe...@gmail.com>.
On Sun, Nov 1, 2009 at 5:30 AM, Avlesh Singh <av...@gmail.com> wrote:
>>
>> The use case on DocumentObjectBinder is that I could override
>> toSolrInputDocument, and if field = ID, I could do: setField("id",
>> obj.getClass().getName() + obj.getId()) or something like that.
>>
>
> Unless I am missing something here, can't you write the getter of id field
> in your solr bean as underneath?
>
> @Field
> private String id;
> public getId(){
>  return (this.getClass().getName() + this.id);
> }

I'm using a code generator for my entities, and I cannot modify the generation.
I need to work out another option :(


> Cheers
> Avlesh
>
> On Fri, Oct 30, 2009 at 1:33 PM, Christian López Espínola <
> penyaskito@gmail.com> wrote:
>
>> On Fri, Oct 30, 2009 at 2:04 AM, Avlesh Singh <av...@gmail.com> wrote:
>> >>
>> >> One thing I thought about is if I can define my own
>> >> DocumentObjectBinder, so I can concatenate my entity names with the
>> >> IDs in the XML creation.
>> >>
>> >> Anyone knows if something like this can be done without modifying
>> >> Solrj sources? Is there any injection or plugin mecanism for this?
>> >>
>> > More details on the use-case please.
>>
>> If I index a Book with ID=3, and then a Magazine with ID=3, I'll be
>> really removing my Book3 and indexing Magazine3. I want both entities
>> to be in the index.
>>
>> The use case on DocumentObjectBinder is that I could override
>> toSolrInputDocument, and if field = ID, I could do: setField("id",
>> obj.getClass().getName() + obj.getId()) or something like that.
>>
>> The goal is avoiding creating all the XMLs to be sent to Solr but
>> having the possibility of modifying them in some way.
>>
>> Do you know how can I do that, or a better way of achieving the same
>> results?
>>
>>
>> > Cheers
>> > Avlesh
>> >
>> > On Fri, Oct 30, 2009 at 2:16 AM, Christian López Espínola <
>> > penyaskito@gmail.com> wrote:
>> >
>> >> Hi Israel,
>> >>
>> >> Thanks for your suggestion,
>> >>
>> >> On Thu, Oct 29, 2009 at 9:37 PM, Israel Ekpo <is...@gmail.com>
>> wrote:
>> >> > On Thu, Oct 29, 2009 at 3:31 PM, Christian López Espínola <
>> >> > penyaskito@gmail.com> wrote:
>> >> >
>> >> >> Hi, my name is Christian and I'm a newbie introducing to solr (and
>> >> solrj).
>> >> >>
>> >> >> I'm working on a website where I want to index multiple entities,
>> like
>> >> >> Book or Magazine.
>> >> >> The issue I'm facing is both of them have an attribute ID, which I
>> >> >> want to use as the uniqueKey on my schema, so I cannot identify
>> >> >> uniquely a document (because ID is saved in a database too, and it's
>> >> >> autonumeric).
>> >> >>
>> >> >> I'm sure that this is a common pattern, but I don't find the way of
>> >> solving
>> >> >> it.
>> >> >>
>> >> >> How do you usually solve this? Thanks in advance.
>> >> >>
>> >> >>
>> >> >> --
>> >> >> Cheers,
>> >> >>
>> >> >> Christian López Espínola <penyaskito>
>> >> >>
>> >> >
>> >> > Hi Christian,
>> >> >
>> >> > It looks like you are bringing in data to Solr from a database where
>> >> there
>> >> > are two separate tables.
>> >> >
>> >> > One for *Books* and another one for *Magazines*.
>> >> >
>> >> > If this is the case, you could define your uniqueKey element in Solr
>> >> schema
>> >> > to be a "string" instead of an integer then you can still load
>> documents
>> >> > from both the books and magazines database tables but your could
>> prefix
>> >> the
>> >> > uniqueKey field with "B" for books and "M" for magazines
>> >> >
>> >> > Like so :
>> >> >
>> >> > <field name="id" type="string" indexed="true" stored="true"
>> >> > required="true"/>
>> >> >
>> >> > <uniqueKey>id</uniqueKey>
>> >> >
>> >> > Then when loading the books or magazines into Solr you can create the
>> >> > documents with id fields like this
>> >> >
>> >> > <add>
>> >> >  <doc>
>> >> >    <field name="id">B14000</field>
>> >> >  </doc>
>> >> >  <doc>
>> >> >    <field name="id">M14000</field>
>> >> >  </doc>
>> >> >  <doc>
>> >> >    <field name="id">B14001</field>
>> >> >  </doc>
>> >> >  <doc>
>> >> >    <field name="id">M14001</field>
>> >> >  </doc>
>> >> > </add>
>> >> >
>> >> > I hope this helps
>> >>
>> >> This was my first thought, but in practice there isn't Book and
>> >> Magazine, but about 50 different entities, so I'm using the Field
>> >> annotation of solrj for simplifying my code (it manages for me the XML
>> >> creation, etc).
>> >> One thing I thought about is if I can define my own
>> >> DocumentObjectBinder, so I can concatenate my entity names with the
>> >> IDs in the XML creation.
>> >>
>> >> Anyone knows if something like this can be done without modifying
>> >> Solrj sources? Is there any injection or plugin mecanism for this?
>> >>
>> >> Thanks in advance.
>> >>
>> >>
>> >> > --
>> >> > "Good Enough" is not good enough.
>> >> > To give anything less than your best is to sacrifice the gift.
>> >> > Quality First. Measure Twice. Cut Once.
>> >> >
>> >>
>> >>
>> >>
>> >> --
>> >> Cheers,
>> >>
>> >> Christian López Espínola <penyaskito>
>> >>
>> >
>>
>>
>>
>> --
>> Cheers,
>>
>> Christian López Espínola <penyaskito>
>>
>



-- 
Cheers,

Christian López Espínola <penyaskito>