mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-12-23 08:36:32 +00:00
{list} Fix duplicate suggestions in Add Books section
Fixes #2584 (Also fix a spelling mistake in a comment in book_search.py)
This commit is contained in:
parent
917569ef0e
commit
dd23bc4d0f
2 changed files with 13 additions and 7 deletions
|
@ -20,7 +20,7 @@ def search(query, min_confidence=0, filters=None, return_first=False):
|
|||
query = query.strip()
|
||||
|
||||
results = None
|
||||
# first, try searching unqiue identifiers
|
||||
# first, try searching unique identifiers
|
||||
# unique identifiers never have spaces, title/author usually do
|
||||
if not " " in query:
|
||||
results = search_identifiers(query, *filters, return_first=return_first)
|
||||
|
|
|
@ -94,7 +94,7 @@ class List(View):
|
|||
return redirect(book_list.local_path)
|
||||
|
||||
|
||||
def get_list_suggestions(book_list, user, query=None):
|
||||
def get_list_suggestions(book_list, user, query=None, num_suggestions=5):
|
||||
"""What books might a user want to add to a list"""
|
||||
if query:
|
||||
# search for books
|
||||
|
@ -103,15 +103,21 @@ def get_list_suggestions(book_list, user, query=None):
|
|||
filters=[~Q(parent_work__editions__in=book_list.books.all())],
|
||||
)
|
||||
# just suggest whatever books are nearby
|
||||
suggestions = user.shelfbook_set.filter(~Q(book__in=book_list.books.all()))
|
||||
suggestions = [s.book for s in suggestions[:5]]
|
||||
if len(suggestions) < 5:
|
||||
suggestions += [
|
||||
suggestions = user.shelfbook_set.filter(
|
||||
~Q(book__in=book_list.books.all())
|
||||
).distinct()[:num_suggestions]
|
||||
suggestions = [s.book for s in suggestions[:num_suggestions]]
|
||||
if len(suggestions) < num_suggestions:
|
||||
others = [
|
||||
s.default_edition
|
||||
for s in models.Work.objects.filter(
|
||||
~Q(editions__in=book_list.books.all()),
|
||||
).order_by("-updated_date")[: 5 - len(suggestions)]
|
||||
)
|
||||
.distinct()
|
||||
.order_by("-updated_date")[:num_suggestions]
|
||||
]
|
||||
# get 'num_suggestions' unique items
|
||||
suggestions = list(set(suggestions + others))[:num_suggestions]
|
||||
return suggestions
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue