Johnczek
Johnczek

Reputation: 657

SOLR many to many with extra column map

Is it possible to store many to many relation with extra column?

This is a situation:

stock_item solr core is core that contains everything about stock item (so name, price, description, ...).

and its taken from stock_item entity. That entity has (aside of other properties that are not important in this question) many to many relation with extra column with stock_item_group entity. Stock item group is entity for storing some stock_item together (so there could be for example "easter" stock item group that contains only stock items that have something in common with easter). Simple many to many relation is easy to insert into solr (there will be property on stock_item core holding list of stock_item_group ids). But, there is that extra column. That column represents order of stock item in stock_item_group (so easter bunny would be first, easter egg seconds, ...).

I have no clue how to insert that into solr (is it possible to store array of map into stock_item core?)

The wnated behavioral is query, where I specify just the stock_item_group id and solr returns list of stock_items ordered by that extra column.

Upvotes: 0

Views: 78

Answers (1)

Alexandre Rafalovitch
Alexandre Rafalovitch

Reputation: 9789

It sounds like you are tracking (group) presence and sort order. If the number of stock items groups is not too high, you could have two dynamic field patterns defined:

  • group_included_[id] (as boolean)
  • group_order_[id] (as int)

And then you just filter on included and sort on order. You could also have included as usual multivalue field if you prefer. You could even skip it and just check for presence of any value in group_order_[id] field, but the performance will be worse.

Upvotes: 1

Related Questions