简体   繁体   English

Solr - 架构帮助(产品属性)

[英]Solr - schema help (product attributes)

I was wondering if any of you could help me with storing product attributes in Solr. 我想知道你们中是否有人可以帮助我在Solr中存储产品属性。 The problem that I have is that product attributes vary depending on the product category. 我遇到的问题是产品属性因产品类别而异。 From what I've understood so far, I'd have to list the fields in my schema. 从我到目前为止所理解的,我必须列出我的架构中的字段。 The number of attributes is rather large and constantly changing - what do you guys suggest? 属性的数量相当大且不断变化 - 你们有什么建议?

For example, a product in the shirts category might have a size attribute but one in the realty category have might have bedrooms attribute. 例如, 衬衫类别中的产品可能具有尺寸属性,但房地产类别中的产品可能具有卧室属性。

(I'm currently planning on constantly importing MySQL data into Solr and use Solr mostly for faceted searching) (我目前正计划不断将MySQL数据导入Solr并主要使用Solr进行分面搜索)

You can set up dynamic fields in solr. 您可以在solr中设置动态字段 In schema.xml, in the <fields> block, you can configure dynamic field definitions like this: 在schema.xml中的<fields>块中,您可以配置动态字段定义,如下所示:

<fields>
    ...

    <dynamicField name="*_t"  type="text"   indexed="true" stored="true" multiValued="false"/>
    <dynamicField name="*_s"  type="string" indexed="true" stored="true" multiValued="false"/>
    <dynamicField name="*_sa" type="string" indexed="true" stored="true" multiValued="true" />
    <dynamicField name="*_d"  type="date"   indexed="true" stored="true" multiValued="false"/>
    <dynamicField name="*_f"  type="sfloat" indexed="true" stored="true" multiValued="false"/>
    <dynamicField name="*_i"  type="sint"   indexed="true" stored="true" multiValued="false"/>
    <dynamicField name="*_ia" type="sint"   indexed="true" stored="true" multiValued="true" />
</fields>

The particular settings you want might be different, but this is the basic idea. 您想要的特定设置可能不同,但这是基本想法。

Consider the first dynamicField definition above. 考虑上面的第一个dynamicField定义。 What it is saying is that you can dynamically add any fields ending _t and these fields will be treated as text fields, will be indexed and stored, and will be treated as a single value (as opposed to an array). 它的含义是你可以动态添加任何以_t结尾的字段,这些字段将被视为文本字段,将被索引和存储,并将被视为单个值(而不是数组)。

You can set up as many dynamic field names as you want, and there is no significance or convention to the names you use. 您可以根据需要设置任意数量的动态字段名称,并且您使用的名称没有任何重要性或约定。 Just set up one dynamicField definition for each data type that you might have. 只需为您可能拥有的每种数据类型设置一个dynamicField定义。

Then, that's it. 然后就是这样。 No need to define your specific fields, just use the suffixes you set up. 无需定义特定字段,只需使用您设置的后缀即可。 So, for example if you used the fields above, you could do an insert with: 因此,例如,如果您使用上面的字段,您可以执行以下插入:

category_s = 'realty'
bedrooms_i = 4

Or you could do an insert with: 或者你可以做一个插入:

category_s = 'shirts'
size_s = 'M'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM