同一个 Solr Core 中的多个索引..? [英] Multiple Indexes in same Solr Core..?

查看:30
本文介绍了同一个 Solr Core 中的多个索引..?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Apache Solr..我有以下场景..:

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

我的 PostGreSQL 数据库中有两个表.一种是汽车".另一个是经销商"

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>

我有一个类似的数据 -- config.xml 用于经销商".它与 Cars 具有相同的字段:name、extra

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

现在在我的 Schema.xml 中,我定义了以下字段:

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"/>

现在我想搜索:Maruti 的名字在哪里"..那么 Solr 如何知道是否要搜索 ::: Cars Field : name OR Dealer Field "name"..??

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"..??

我已阅读以下链接:http://wiki.apache.org/solr/MultipleIndexes

但我无法理解它是如何工作的..??

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

阅读该链接后:我在我的汽车经销商 *data-config.xml* 中创建了另一个字段,例如:

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

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

然后在 Schema.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

但它确实有效..!!

那我该怎么办..??

推荐答案

如果汽车和经销商的字段相同,您可以使用一个索引和一个对象定义如下:

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>

这对汽车和经销商都适用(所以你不需要有 2 个索引),你将使用类型"字段来挑选你想要经销商"还是汽车"(我'正在使用相同的系统过滤掉相似类型的对象,只有微小的语义"差异)

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)

您还需要将 stored="true" 添加到要检索的字段中,否则您将只能使用它们进行搜索(因此 index="true")

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")

这篇关于同一个 Solr Core 中的多个索引..?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆