From d3c181cacbc4ac5283a20feb9da1fd4bc15ca2fb Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Sat, 2 Jan 2021 16:09:54 -0800 Subject: [PATCH] Re-sorts search results after deduplication --- bookwyrm/connectors/self_connector.py | 5 +++-- bookwyrm/tests/connectors/test_self_connector.py | 6 +++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/bookwyrm/connectors/self_connector.py b/bookwyrm/connectors/self_connector.py index 04fea735..0c21e7bc 100644 --- a/bookwyrm/connectors/self_connector.py +++ b/bookwyrm/connectors/self_connector.py @@ -23,6 +23,7 @@ class Connector(AbstractConnector): search_results.append(self.format_search_result(result)) if len(search_results) >= 10: break + search_results.sort(key=lambda r: r.confidence, reverse=True) return search_results @@ -75,10 +76,10 @@ def search_identifiers(query): def search_title_author(query, min_confidence): ''' searches for title and author ''' - print('DON"T BOTHER') vector = SearchVector('title', weight='A') +\ SearchVector('subtitle', weight='B') +\ - SearchVector('authors__name', weight='C') + SearchVector('authors__name', weight='C') +\ + SearchVector('series', weight='D') results = models.Edition.objects.annotate( search=vector diff --git a/bookwyrm/tests/connectors/test_self_connector.py b/bookwyrm/tests/connectors/test_self_connector.py index a28ca12a..0fc78955 100644 --- a/bookwyrm/tests/connectors/test_self_connector.py +++ b/bookwyrm/tests/connectors/test_self_connector.py @@ -48,6 +48,7 @@ class SelfConnector(TestCase): edition = models.Edition.objects.create( title='Edition of Example Work', published_date=datetime.datetime(1980, 5, 10, tzinfo=timezone.utc), + parent_work=models.Work.objects.create(title='') ) # author text is rank C edition.authors.add(author) @@ -55,18 +56,21 @@ class SelfConnector(TestCase): # series is rank D models.Edition.objects.create( title='Another Edition', - series='Anonymous' + series='Anonymous', + parent_work=models.Work.objects.create(title='') ) # subtitle is rank B models.Edition.objects.create( title='More Editions', subtitle='The Anonymous Edition', + parent_work=models.Work.objects.create(title='') ) # title is rank A models.Edition.objects.create(title='Anonymous') # doesn't rank in this search edition = models.Edition.objects.create( title='An Edition', + parent_work=models.Work.objects.create(title='') ) results = self.connector.search('Anonymous')