From 6470033ac9f2f8f663b2fd8a6022cc9680708e97 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Sat, 26 Jun 2021 16:20:18 -0700 Subject: [PATCH] Fixes search query syntax mad about the lack of django docs on this, jeez --- bookwyrm/connectors/self_connector.py | 2 +- bookwyrm/migrations/0077_auto_20210623_2155.py | 2 +- bookwyrm/tests/connectors/test_self_connector.py | 5 +++-- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/bookwyrm/connectors/self_connector.py b/bookwyrm/connectors/self_connector.py index 36409bc5b..b5492b737 100644 --- a/bookwyrm/connectors/self_connector.py +++ b/bookwyrm/connectors/self_connector.py @@ -143,7 +143,7 @@ def search_title_author(query, min_confidence, *filters): """searches for title and author""" query = SearchQuery(query, config="simple") | SearchQuery(query, config="english") results = ( - models.Edition.objects.annotate(rank=SearchRank("search_vector", query)) + models.Edition.objects.annotate(rank=SearchRank(F("search_vector"), query)) .filter(*filters, search_vector=query, rank__gt=min_confidence) .order_by("-rank") ) diff --git a/bookwyrm/migrations/0077_auto_20210623_2155.py b/bookwyrm/migrations/0077_auto_20210623_2155.py index c915badd0..a73c43825 100644 --- a/bookwyrm/migrations/0077_auto_20210623_2155.py +++ b/bookwyrm/migrations/0077_auto_20210623_2155.py @@ -44,7 +44,7 @@ class Migration(migrations.Migration): setweight(to_tsvector('simple', coalesce(new.title, '')), 'A') ) || setweight(to_tsvector('english', coalesce(new.subtitle, '')), 'B') || - (SELECT setweight(to_tsvector('simple', coalesce(array_to_string(array_agg(bookwyrm_author.name), ' '), '')), 'B') + (SELECT setweight(to_tsvector('simple', coalesce(array_to_string(array_agg(bookwyrm_author.name), ' '), '')), 'C') FROM bookwyrm_book LEFT OUTER JOIN bookwyrm_book_authors ON bookwyrm_book.id = bookwyrm_book_authors.book_id diff --git a/bookwyrm/tests/connectors/test_self_connector.py b/bookwyrm/tests/connectors/test_self_connector.py index 11c15826a..02c0c9a4f 100644 --- a/bookwyrm/tests/connectors/test_self_connector.py +++ b/bookwyrm/tests/connectors/test_self_connector.py @@ -70,15 +70,16 @@ class SelfConnector(TestCase): # title is rank A models.Edition.objects.create(title="Anonymous") # doesn't rank in this search - edition = models.Edition.objects.create( + models.Edition.objects.create( title="An Edition", parent_work=models.Work.objects.create(title="") ) results = self.connector.search("Anonymous") - self.assertEqual(len(results), 3) + self.assertEqual(len(results), 4) self.assertEqual(results[0].title, "Anonymous") self.assertEqual(results[1].title, "More Editions") self.assertEqual(results[2].title, "Edition of Example Work") + self.assertEqual(results[3].title, "Another Edition") @patch("bookwyrm.preview_images.generate_edition_preview_image_task.delay") def test_search_multiple_editions(self, _):