同一Solr核心中的多个索引..?

时间:2012-03-05 10:07:24

标签: solr indexing

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

我的PostGreSQL数据库中有两个表。一个是“ 汽车 ”。其他是“经销商

现在我有 Cars 的数据配置文件,如下所示:

    

<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 etc

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

<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将如何知道是否搜索:::汽车领域:名称或经销商字段“名称”.. ??

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

但我无法理解它是如何起作用的。??

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

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

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

然后在Schema.xml中我创建了一个新字段:

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

然后我查询了类似的内容:

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

但它工作了...... !!

那我该怎么办.. ??

2 个答案:

答案 0 :(得分:5)

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

<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个索引)并且您将使用“类型”字段来理清您是否需要“经销商”或“汽车”(i使用相同的系统过滤掉相似类型的对象只有一个较小的“semanthical”差异

你还需要在你想要检索的字段中添加stored =“true”,否则你只能用它们进行搜索(因此index =“true”)

答案 1 :(得分:2)

在类型字段中添加默认值将确保将类型值设置为cars|dealer

您必须单独索引来源。然后使用复制字段,您可以轻松过滤cars|dealer

这似乎有点棘手,并且在上面提到的多索引链接中没有得到很好的解释。

相关问题