簡體   English   中英

solr模式設計,用於多對多的實體定義

[英]solr schema design for many to many entity definitions

我正在嘗試為產品和供應商之間存在多對多關系的方案設計模式。 搜索可以從以產品為中心的方式或以供應商為中心的方式完成。 產品可由許多供應商提供,供應商將擁有許多產品。 以下是我正在考慮的解決方案,但似乎在字段定義中存在大量冗余,我是否需要2個實體定義來支持以產品或供應商為中心的搜索。 看起來不太理想。

在搜索供應商時,“產品”可以定義為“multiValue = true”在搜索產品時,“供應商”可以定義為“multiValue = true”

<!-- Field definitions to support supplier search -->
<field name="s_supplier" type="string" indexed="true" stored="true" >
<field name="s_product"  type="string" indexed="true" stored="true" multiValue="true">

<!-- Field definition to support product search -->
<field name="p_product"  type="string" indexed="true" stored="true" >
<field name="p_supplier"  type="string" indexed="true" stored="true" multiValue="true">

datahandler中的實體定義是

<entity name="products" ....>
   <field name="p_product" column="">
   <entity name="suppliers">
      <field name="p_supplier">
    </entity>
</entity>

<entity name="suppliers" ....>
   <field name="s_supplier" column="">
   <entity name="products">
      <field name="s_product" column="">
    </entity>
</entity>

Solr搜索引擎的優點在於您可以選擇一種模式定義,無論是產品還是以供應商為中心,然后利用Solr的強大功能來實現您期望的結果。 假設您使用以產品為中心的產品,使用以下方法:

<field name="product" type="string" indexed="true" stored="true" > 
<field name="supplier" type="string" indexed="true" stored="true" multiValue="true">

您現在可以通過針對產品現場product:my product運行查詢來搜索product:my product ,然后如果您要搜索特定供應商,您可以使用supplier:my supplier ,因為供應商字段是與之相關的多值字段每個產品,您將獲得與供應商相關聯的所有產品。

提高靈活性的另一個選擇是利用示例schema.xml文件中定義的text字段,並使用'copyfield函數將供應商和產品值復制到一個字段,然后您可以搜索它以獲得所有字段返回的文檔與供應商或產品字段中的查詢字詞匹配。

這是一個示例,仍然使用上面定義的字段。

<field name="text" type="text" indexed="true" stored="false" multiValued="true"/>
<copyField source="product" dest="text" />
<copyField source="supplier" dest="text" />

然后,如果您搜索text:my term可以是產品或供應商,並且將返回索引中與該字段匹配的所有文檔。 請注意,文本字段具有應用於其的特定索引和查詢時間分析器,因此您應該知道正在應用的內容。

此外,如果您需要生成唯一供應商列表,則可以利用Solr Faceting從索引中的所有文檔中獲取該列表,或僅與當前搜索條件相關。

有關這些主題的更多詳細信息,請參閱以下一些參考資料:

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM