多对多实体定义的 solr 模式设计

发布于 2024-12-04 21:54:12 字数 1231 浏览 0 评论 0原文

我正在尝试为产品和供应商之间存在多对多关系的场景设计一个架构。搜索可以以产品为中心的方式或以供应商为中心的方式进行。一种产品可以由许多供应商提供,并且供应商将有许多产品。以下是我正在考虑的解决方案,但似乎字段定义中有很多冗余,我是否需要 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">

数据处理程序中的实体定义是

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

I am trying to design a schema for a scenarios where there is a Many to Many relation between Products and Supplier. Search can be done from product centric way or supplier centric way. A product can be supplied by many Supplier and Supplier will have many product. Following is the solution I am thinking, but it seems like there is lot of redundancy in field definitions, do I need 2 entity definitions to support Product or Supplier centric searches. Does not look optimum.

When doing a search for a Supplier, "product" can be defined "multiValue=true" When doing a search for a product, "supplier" can be defined "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">

entity definition in datahandler is

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

假情假意假温柔 2024-12-11 21:54:12

Solr 搜索引擎的优点在于,您只需选择一个以产品或供应商为中心的模式定义,然后利用 Solr 的强大功能来实现您想要的结果。假设您采用以产品为中心的产品,使用以下命令:

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

您现在只需通过对产品字段产品:我的产品运行查询来搜索产品,然后如果您想搜索对于特定的供应商,您只需使用 supplier:my seller 即可,并且由于供应商字段是与每个产品关联的多值字段,因此您将获取与该供应商关联的所有产品。

获得更大灵活性的另一个选项是利用示例 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 从索引中的所有文档或仅与当前搜索条件相关的文档中获取该列表。

有关这些主题的更多详细信息,请参阅以下参考文献:

The beauty of the Solr search engine is that you can just pick one schema definition, either product or supplier centric and then leverage the power of Solr to achieve your desired results. Let's say that you go with a product centric one, using the following:

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

You can now search for products just by running a query against the product field product:my product and then if you want to search for a specific supplier, you can just use supplier:my supplier and because the supplier field is a multivalued field associated with each product, you will get all the products back where that supplier is associated.

Another option for greater flexibility would be to leverage the text field that is defined in the example schema.xml file and use the 'copyfield function to copy both supplier and product values to one field and you can then search it for either and will get all documents returned that match the query term on either the supplier or product field.

Here is an example, still using the fields defined above.

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

Then if you search for text:my term it can be either product or supplier and all documents in the index that match that field will be returned. Please note that the text field has specific index and query time analyzers applied to it, so you should be aware of what is being applied.

Also, if you need to produce a list of unique suppliers, you can leverage Solr Faceting to get that list from all of the documents in the index or only related to the current search criteria.

Please see some of the following references for more details on these topics:

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文