Skip to content

Commit

Permalink
Do not modify original book object within loop
Browse files Browse the repository at this point in the history
  • Loading branch information
caleb531 committed Nov 27, 2017
1 parent 3ec0930 commit 1b96ab2
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions yvs/filter_refs.py
Expand Up @@ -100,11 +100,14 @@ def get_matching_books(books, query):
book_name_words = split_book_name_into_parts(book['name'])
for w, book_word in enumerate(book_name_words):
if book_word.startswith(query['book']):
# Give more priority to book names that are matched sooner
# (e.g. if the query matched the first word of a book name, as
# opposed to the second or third word)
book['priority'] = ((w + 1) * 100) + b
matching_books.append(book)
matching_books.append({
'id': book['id'],
'name': book['name'],
# Give more priority to book names that are matched sooner
# (e.g. if the query matched the first word of a book name,
# as opposed to the second or third word)
'priority': ((w + 1) * 100) + b
})
break

matching_books.sort(key=itemgetter('priority'))
Expand Down

0 comments on commit 1b96ab2

Please sign in to comment.