Ramandeep Singh
Ramandeep Singh

Reputation: 5253

Multiple Indexes in same Solr Core..?

I am using Apache Solr..I have the following Scenario.. :

I have Two table in my PostGreSQL database. One is "Cars". Other is "Dealers"

Now i have a data-config file for Cars like the following :

<document name="offerings">
    <entity name="jc_offerings" query="select * from jc_offerings" >
        <field column="id" name="id" />
        <field column="name" name="name" />
        <field column="display_name" name="display_name" />
        <field column="extra" name="extra" />
    </entity>
</document>

I have a similar data--config.xml for "Dealers". It has the same fields as Cars : name, extra etc

Now in my Schema.xml , i have defined the following fields :

<fields>
  <field name="id" type="string"   indexed="true" />
  <field name="name" type="name"  indexed="true" />
  <field name="extra" type="extra"  indexed="true"  /> 

  <field name="CarsText" type="text_general" indexed="true" 
    stored="true" multiValued="true"/>
</fields>

<uniqueKey>id</uniqueKey>
<defaultSearchField>CarsText</defaultSearchField>
<copyField source="name" dest="CarsText"/>
<copyField source="extra" dest="CarsText"/>

Now i want to search like : "where name is Maruti"..So how will Solr know Whether to Search ::: Cars Field : name OR Dealer Field "name"..??

I have read to the following link : http://wiki.apache.org/solr/MultipleIndexes

But i am not able to understand how is works..??

After reading that link : I made another field in My Cars and Dealers *data-config.xml* .. Something like :

<field name="type" value="car" />  : in Cars date-config.xml

and

<field name="type" value="dealer" />  : in Cars date-config.xml

And then in Schema.xml i created a new field :

<field name="type" type="string"   indexed="true" stored="true" />  

And then i queried something like :

localhost:8983/solr/select?q=name:Maruti&fq=type:dealer

But it dint Worked..!!

So what should i do..??

Upvotes: 3

Views: 8255

Answers (2)

Peter William
Peter William

Reputation: 21

Adding a default value to the type field will ensure the type value being set to cars|dealer.

You will have to index the sources separately. Then use copy field and you can easily filter on either cars|dealer.

This does seem a bit tricky and is not explained well in the muti-indexes link referred to above.

Upvotes: 2

Samuele Mattiuzzo
Samuele Mattiuzzo

Reputation: 11038

if the fields are the same for both cars and dealers, you could use one index with an object defined like so:

<fields>
  <field name="id" type="string"   indexed="true" stored="true"/>
  <field name="name" type="name"  indexed="true" stored="true" />
  <field name="extra" type="extra"  indexed="true" stored="true" /> 
  <field name="description_text" type="text_general" indexed="true" stored="true" multiValued="true"/>
  <field name="type" type="string" indexed="true" stored="true" />
</fields>

this will work for both cars and dealers (so you don't need to have 2 indexes) and you'll use the "type" field to sort out if you want a "dealer" or a "car" (i'm using the same system to filter out similar types of objects with only a minor "semanthical" difference)

also you'll need to add stored="true" to the fields you want to retrieve, or you'll be only able to use them for searching (hence that index="true")

Upvotes: 5

Related Questions