如何为solr中的字段数组定义多值

时间:2013-08-08 14:10:09

标签: solr nested-attributes

我有xml文档,其中包含多组标记。对于例如以下文档中的<Address>标记。换句话说,父标签地址发生2次。

我想搜索Name=ABCDZipCode=33333,并希望solr返回类似于下面给出的“响应文档”的响应。是否可以在solr4.0中执行此操作而不将Address定义为多值单个字段,所有子字段由分隔符分隔?

DOC

<doc>
      <Name>ABCD</Name>
      <CompanyName>1234</CompanyName>
      <Address>
          <AddressLine1> 1725 ABCD Drive </AddressLine1>
          <AddressLine2> </Address Line2>
          <City>Miami</City>
          <State>FL</State>
          <Zipcode>33333</Zipcode>
          <AddressType>Home</AddressType>
      </Address>
      <Address>
          <AddressLine1> 16551 business blvd </AddressLine1>
          <AddressLine2> </Address Line2>
          <City>Miami</City>
          <State>FL</State>
          <Zipcode>33333</Zipcode>
          <AddressType>Business</AddressType>
      </Address>
</doc>
<doc>
      <Name>XYZWR</Name>
      <CompanyName>1234</CompanyName>
      <Address>
          <AddressLine1> 1725 ABCD Drive </AddressLine1>
          <AddressLine2> </Address Line2>
          <City>Miami</City>
          <State>FL</State>
          <Zipcode>33333</Zipcode>
          <AddressType>Home</AddressType>
      </Address>
      <Address>
          <AddressLine1> 16551 business blvd </AddressLine1>
          <AddressLine2> </Address Line2>
          <City>Phoenix</City>
          <State>AZ</State>
          <Zipcode>33333</Zipcode>
          <AddressType>Business</AddressType>
      </Address>
</doc>

响应DOC

   <doc>
          <Name>ABCD</Name>
          <CompanyName>1234</CompanyName>
          <Address>
              <AddressLine1> 1725 ABCD Drive </AddressLine1>
              <AddressLine2> </Address Line2>
              <City>Miami</City>
              <State>FL</State>
              <Zipcode>33333</Zipcode>
              <AddressType>Home</AddressType>
          </Address>
          <Address>
              <AddressLine1> 16551 business blvd </AddressLine1>
              <AddressLine2> </Address Line2>
              <City>Miami</City>
              <State>FL</State>
              <Zipcode>33333</Zipcode>
              <AddressType>Business</AddressType>
          </Address>
    </doc>

此致

1 个答案:

答案 0 :(得分:0)

我们必须存储非规范化的。没有其他办法了。所以,我们存储像

这样的字段
home_addressline1
home_zipcode
etc.,

进行搜索,您可以拥有动态字段 - 两种动态字段,然后有一个可以适当复制到这些动态字段中的复制字段

address_*
*_home (and/or) *_business etc.,

当用户想搜索邮政编码并且不关心地址的哪个“类型”时,你使用address_ *,而当用户只想搜索“家庭类型”时,你使用* _home并请求开始注入仅用于搜索某种地址类型:)