我有一个具有下一个结构的索引:
+----+-----------+---------+--------------+
| id | entity_id | content | weight_field |
+----+-----------+---------+--------------+
| 1 | 1 | car | 1.2 |
+----+-----------+---------+--------------+
| 2 | 1 | desert | 1.45 |
+----+-----------+---------+--------------+
| 3 | 1 | water | 1.55 |
+----+-----------+---------+--------------+
| 4 | 2 | water | 1.1 |
+----+-----------+---------+--------------+
| 5 | 2 | desert | 1.9 |
+----+-----------+---------+--------------+
有人可以告诉我是否可以SUM()
通过分组字段值?我试过这个
SELECT SUM(weight_field) AS sort, entity_id FROM test_index WHERE MATCH ('@content car|desert|water') GROUP BY entity_id ORDER BY sort DESC
但出现错误:
syntax error, unexpected '(', expecting $end near '()'
我希望得到下一个结果:
+------+-----------+
| sort | entity_id |
+------+-----------+
| 4.2 | 1 |
+------+-----------+
| 3.0 | 2 |
+------+-----------+
第二种对我有好处的方法:使用自定义weight_field
(包含浮点值1.563
等1.02
)对结果进行排名。但我不确定这可能与
OPTION ranker=...