简体   繁体   English

Peewee rank()方法给出负分数。 是这样做的吗?

[英]Peewee rank() method giving negative scores. Is it designed to do so?

from the peewee docs: 来自peewee文档:

Generate an expression that will calculate and return the quality of the search match. 生成一个表达式,该表达式将计算并返回搜索匹配的质量。 This rank can be used to sort the search results. 该等级可用于对搜索结果进行排序。 The lower the rank, the better the match. 等级越低,匹配越好。

I am currently testing the full-text search feature that Peewee provides. 我目前正在测试Peewee提供的全文搜索功能。 The docs mentions that lower scores are better matches but all I am getting are negative scores, is it designed to return negative scores? 该文档提到较低的分数是更好的匹配,但是我得到的只是负分数,它旨在返回负分数吗?

query: 查询:

query = (models.Post
         .select(models.Post.title, models.Post.content, models.FTSPost.rank().alias('score'))
         .join(models.FTSPost, on=(models.Post.id == models.FTSPost.post_id))
         .where(models.FTSPost.match(search_query))
         .order_by(models.SQL('score').desc()))

Yes, it gives negative scores so that when you order by rank (ascending) you get the results in the correct order. 是的,它给出的分数是负数,因此当您按等级排序(升序)时,您将以正确的顺序获得结果。

This may conflict with what you found on my blog, for instance, as earlier versions did not do this and required ranking by score descending. 例如,这可能与您在我的博客上找到的内容冲突,因为较早的版本没有做到这一点,并且要求得分按降序排列。

But, basically, if you're on a newer version of peewee, just order by score ASCending and you should be OK. 但是,基本上,如果您使用的是peewee的较新版本,只需按分数ASCending进行排序,就可以了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM