Alex
Alex

Reputation: 38529

Solr - Indexing products with attributes as Key / Value pair

I’m currently looking at developing a solr application to index products on our e-commerce website.

Some example fields in the schema are:

Attributes are a list of key-value pairs. For example:

Type = Rose
Position = Full Sun
Position = Shade
Colour = Red

I am going to store the fields, so that my pages can be generated from a search result.

How is it best to represent these?

I was thinking of maybe having some dynamic fields for indexing: attribute_* for example (attribute_position) And then “attribute” for stored value (For returning, for displaying) - storing multiple fields The value of an “attribute” field could be (for example) Position|Full Sun - then let the client handle the displaying?

Are there any better ways of doing this?

As a footnote- I will be using Solrnet as a client for querying (probably not relevant)

Upvotes: 3

Views: 4037

Answers (1)

rfeak
rfeak

Reputation: 8204

First, I would not recommend storing your entire document in your search engine. The only thing you should store in Solr is those things that you wish to search on. Yes, it supports storing more, however, taking advantage of this can cause issues down the road with index size, master/slave replication time, etc. Ideally, the only thing in Solr is things you wish to search/sort on and a document ID that is unique enough to fetch document data with from another source that is optimized for storing .... documents.

However, if you decide to ignore this advice, then you can easily store your name value pairs in a single field. If your name value pairs have a limited character set, you can easily concatenate the name value pairs into a single string. Then, parse them on the way out when you are forming your web page for display. There's no need to come up with a more complex schema to support this. Multiple fields for storing these will only increase your index overhead, which buys you nothing.

Upvotes: 3

Related Questions