如何以百分比形式获取mysql匹配结果?
我在 mysql 中使用 Match (Col1) Against (Val) 。
select match(body) against(body_var) from articles;
现在,如果完全匹配,我将得到数字形式的结果(例如 14.43)。 这个数字是什么意思?主要问题是我可以得到百分比形式的结果(例如0.94)
感谢您的帮助
I am using Match (Col1) Against (Val) in mysql.
select match(body) against(body_var) from articles;
now in case of completely match i am getting result as a number (for example 14.43).
what does this number mean? and the main question is can i get the result in percentage form (for example 0.94)
thanks for your help
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
可能有一种更简单的方法来做到这一点..不知怎的,我掉进了这个兔子洞..但它经过测试并且有效(返回结果的百分比),
它返回一条记录/结果,其中包含 mPercent 列
您也可以拥有它四舍五入到小数点后两位...
正如我所说..我对 358 行和 50 个匹配项进行了测试
50/350 = 0.1396648...(第一个结果)
舍入结果为 0.14
如果您希望将单个结果的相关性值转换为百分比 - 这实际上不会发生...
来自 MATCH/AGAINST 的相关性值并不是匹配百分比的良好指标。这是通过互联网深入介绍.. 搜索“将相关性值转换为百分比”...
如果您想按相关性匹配百分比对结果进行排序,并且第一个结果始终具有 100% 相关性,您可以这样做
...尝试获取像 PHP 的相似文本这样的值 - 你最好将这项工作转移给客户端...
全文搜索相关性是用什么来衡量的?
http://forums.mysql.com/read.php?107,125239,146610#msg-146610
http://seminex.blogspot.com/2005/06/mysql-relevance-in-fulltext-search.html
There is probably a MUCH easier way to do this.. Somehow i fell down the rabbit hole on this one.. But its tested and works (returns percentage of results)
it returns one record/result with the column mPercent
You could also have it round to two decimal places...
As i said.. I tested it against 358 rows with 50 matches
50/350 = 0.1396648... (for first result)
0.14 for rounded result
If you are looking to convert the relevance value to a percent for a single result - it isnt really going to happen...
The relevance value from the MATCH/AGAINST is not a good indicator of percent match.. This is covered in depth throught the internet.. Search for "Convert Relevance value to percent" ...
If you wanted to order your results by relevence match percent, with the first result always having 100% relevence, you can do that...
As for trying to get a value like PHP's similar_text - you are better to offload that work to the client...
Full-text search relevance is measured in?
http://forums.mysql.com/read.php?107,125239,146610#msg-146610
http://seminex.blogspot.com/2005/06/mysql-relevance-in-fulltext-search.html
我想出的一个解决方法是找到最佳匹配,并使用它们来获得相对于这些最大值的百分比值,这在这种情况下可能并不完全有用,但它确实给了你一个想法。
我使用这种方法来查找重复项,首先插入行,然后运行此查询,最佳匹配当然是同一行。
首先,我必须选择最佳匹配:
您当然可以添加多个列,但必须首先创建适当的全文搜索索引。
完整查询取第一次查询的结果作为参考,可以将比例更改为0.5,0.5意味着获得的分数必须>最佳分数的50%,如果你想获得所有结果,删除比较表达式。
我不认为这是最好的解决方案,但它在我的情况下效果很好。
A work around i came up with is to find the best matches, and use them to have percentage values relative to these maxes, this may not be fully useful in this case, but it sure gives you an idea.
I use this method to look for duplicates, first i insert the row and then i run this query, the best match of course is the same row.
First i have to select the best match :
You can of course add multiple columns, but you must create the appropriate full text search indexes first.
The full query takes the result from the first query and use them as references, you can change the ratio of 0.5, 0.5 means that the score obtained must be >50% of the best score, if you want to get all the results, remove the comparison expression.
I don't believe this is the best solution, but it does well in my case.