0

from the peewee docs:

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. 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()))
Community
  • 1
  • 1
Wagdet
  • 287
  • 2
  • 7

1 Answers1

2

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.

coleifer
  • 24,887
  • 6
  • 60
  • 75