I kinda want to do
option ranker=expr('sum(lcs=field_len)');
Ie the want to favour where the ‘whole’ field matches the query.
But want to to be the length of the specific field. I can do
>select id,tag,tag_len,weight() from tagsk where match('Mountain')
option ranker=expr('sum(lcs=tag_len)');
+--------+--------------------------+---------+----------+
| id | tag | tag_len | weight() |
+--------+--------------------------+---------+----------+
| 8 | Mountain | 1 | 1 |
| 1812 | Mountainside | 1 | 1 |
| 3427 | mountains | 1 | 1 |
| 19681 | Snowdon | 1 | 1 |
| 60516 | Goatfell | 1 | 1 |
| 60518 | Arkle | 1 | 1 |
| 60999 | tryfan | 1 | 1 |
| 73617 | mountaineers | 1 | 1 |
| 76940 | mountaineer | 1 | 1 |
| 167 | Divis Mountain | 2 | 0 |
| 1661 | mountain railway | 2 | 0 |
| 1832 | snowdon mountain railway | 3 | 0 |
Where tag
is the field, can access the _len
attribute by name.
But the sum()
is looping over all the fields and want to be the specific the length of the specific matched field.
The above query demonstrates the issue, in that (for example), Snowdon is listed with rank of 1, but has a lcs
of zero with the tag
field (it some OTHER field that lcs
matches tag_len
! caption_len
!= 1 - the matched field)
(my real query is more complicated, this is a ‘simplified’ example)
Know there is a kinda workaround, with user_weight
option ranker=expr('sum(if(user_weight=10,lcs=tag_len,0))'), field_weights=(tag=10)
works because user_weight
is the weight of the specific field, so can be sensitive to specific fields inside sum()
. But gets messy with lots of fields (nested IFs with lots of different weights), the above only works with one field.
hoping for something simpler. Also don’t want the ‘side effect’ of changing the weight - eg in the internal ranking.