diff --git a/bookwyrm/book_search.py b/bookwyrm/book_search.py index f9bb57dfc..822c87f01 100644 --- a/bookwyrm/book_search.py +++ b/bookwyrm/book_search.py @@ -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) diff --git a/bookwyrm/views/list/list.py b/bookwyrm/views/list/list.py index 1adf7a679..b4dfbd0ea 100644 --- a/bookwyrm/views/list/list.py +++ b/bookwyrm/views/list/list.py @@ -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