开发者

Solr - schema help (product attributes)

开发者 https://www.devze.com 2023-02-05 23:00 出处:网络
I was wondering if any of you could help me with storing product attributes in Solr. The problem that I have is that product attributes vary depending on the product category. From what I\'ve understo

I was wondering if any of you could help me with storing product attributes in 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 sug开发者_StackOverflow社区gest?

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)


You can set up dynamic fields in solr. In schema.xml, in the <fields> block, you can configure dynamic field definitions like this:

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

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.

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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号