lucene-solr-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Christian López Espínola <penyask...@gmail.com>
Subject Re: Indexing multiple entities
Date Sun, 01 Nov 2009 09:34:05 GMT
On Sun, Nov 1, 2009 at 5:30 AM, Avlesh Singh <avlesh@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 <avlesh@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 <israelekpo@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>

Mime
View raw message