Answer the question
In order to leave comments, you need to log in
How to implement custom sorting on Sphinx?
Greetings!
Essence:
There is an index of product offers, in which, in addition to the basic data for faceted and full-text search, there are JSON format attributes:
1) Attribute with the name "similar_from". This attribute contains an array of IDs of similar products for which this product is similar .
+-------+---------------------------------+
| id | similar_from |
+-------+---------------------------------+
| 1 | [2, 3] |
+-------+---------------------------------+
| 2 | [1, 3] |
+-------+---------------------------------+
| 3 | [1, 2] |
+-------+---------------------------------+
+-------+---------------------------------+
| id | similar |
+-------+---------------------------------+
| 1 | [3, 2] |
+-------+---------------------------------+
| 2 | [3, 1] |
+-------+---------------------------------+
| 3 | [2, 1] |
+-------+---------------------------------+
Answer the question
In order to leave comments, you need to log in
You can try this: for each "similar" product, write a json dictionary containing the id of the product it looks like as a key, and the position in the "similar" product of the corresponding product as a value.
Then to get similar to the product with id=1 there will be something like
SELECT id, related_pos.1 AS position WHERE position != 0 ORDER BY position
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question