Merge pull request #3133 from dato/search_results_fix_work_order

Do not create a set for already-distinct query result
This commit is contained in:
Mouse Reeve 2023-11-29 15:27:57 -08:00 committed by GitHub
commit cf1afefc84
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 8 deletions

View file

@ -137,7 +137,7 @@ def search_title_author(
# filter out multiple editions of the same work
list_results = []
for work_id in set(editions_of_work[:30]):
for work_id in editions_of_work[:30]:
result = (
results.filter(parent_work=work_id)
.order_by("-rank", "-edition_rank")

View file

@ -26,10 +26,10 @@ class BookSearch(TestCase):
parent_work=self.work,
isbn_10="1111111111",
openlibrary_key="hello",
pages=150,
)
self.third_edition = models.Edition.objects.create(
title="Edition with annoying ISBN",
title="Another Edition with annoying ISBN",
parent_work=self.work,
isbn_10="022222222X",
)
@ -76,16 +76,21 @@ class BookSearch(TestCase):
def test_search_title_author(self):
"""search by unique identifiers"""
results = book_search.search_title_author("Another", min_confidence=0)
results = book_search.search_title_author("annoying", min_confidence=0)
self.assertEqual(len(results), 1)
self.assertEqual(results[0], self.second_edition)
self.assertEqual(results[0], self.third_edition)
def test_search_title_author_return_first(self):
"""search by unique identifiers"""
results = book_search.search_title_author(
"""sorts by edition rank"""
result = book_search.search_title_author(
"Another", min_confidence=0, return_first=True
)
self.assertEqual(results, self.second_edition)
self.assertEqual(result, self.second_edition) # highest edition rank
def test_search_title_author_one_edition_per_work(self):
"""at most one edition per work"""
results = book_search.search_title_author("Edition", 0)
self.assertEqual(results, [self.first_edition]) # highest edition rank
def test_format_search_result(self):
"""format a search result"""