简体   繁体   中英

Store category information in Solr

I have product information stored in my solr database. A product can be a part of multiple categories.

Now, I want to store information about those categories inside the product which belongs in those categories. (Is there any other way?)

So, say a product A belongs to category C1 and C2 with ids I1 and I2. Now how do i store this mapping of I1 to C1 in my product A? What should be the schema to do so?

But, if a simply store a list of ids, names and some other data(say urls), then the mapping of each id to name or url will be lost. Like this:

<field name="category_ids" type="tints" indexed="true" stored="true"/>
<field name="category_names" type="strings" indexed="true" stored="true"/>

So how should I store documents?

The way you've described works - Solr will keep the sequence between fields the same, so you can assume that the first value in the field category_ids corresponds to the first value in the field category_names . We use this to index more complex objects in several multi value fields.

A second solution is to use the category id to look up the actual category information in your middleware, querying the database for the related information. This will avoid having to reindex all documents for a category if the name changes (except if you use the name for querying, which will require you to do a re-index regardless of solution selected).

A third solution would be to have a field containing both id, name in a serialized form, such as 3;Laptops or as JSON, and just store the field while not indexing it (and use an indexed, non-stored field for actual searching).

You can also use child documents for something like this, but my personal opinion is that it'll give you quite a bit of unnecessary complexity.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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