On Thu, Oct 29, 2009 at 3:31 PM, Christian López Espínola <
penyask...@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
-- 
"Good Enough" is not good enough.
To give anything less than your best is to sacrifice the gift.
Quality First. Measure Twice. Cut Once.

Reply via email to