X-Git-Url: https://git.mdrn.pl/wolnelektury.git/blobdiff_plain/bf44c40468133304afaf5fac1676bcaab7db4969..a7a0a535382be1fd706c3faca3a81201978ba587:/src/search/mock_search.py diff --git a/src/search/mock_search.py b/src/search/mock_search.py index 3bd7b9371..33d2a5eaf 100644 --- a/src/search/mock_search.py +++ b/src/search/mock_search.py @@ -1,8 +1,7 @@ -# -*- coding: utf-8 -*- # This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later. # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information. # -from mock import Mock +from unittest.mock import Mock from catalogue.models import Book, Tag from random import randint, choice @@ -20,11 +19,14 @@ class Search(Mock): index = MockIndex() - @staticmethod - def _find_some_books(query_terms=None, max_results=20): + def search_words(self, words, fields, required=None, book=True, picture=False): from .index import SearchResult - qs = Book.objects.order_by('?') + max_results = 20 + + if picture: return [] + + qs = Book.objects.filter(findable=True).order_by('?') results = [] for book in qs[:randint(1, max_results)]: doc = { @@ -32,19 +34,7 @@ class Search(Mock): 'book_id': book.pk, 'published_date': randint(1000, 1920), } - res = SearchResult(doc, how_found='mock', query_terms=query_terms) + res = SearchResult(doc, how_found='mock', query_terms=words) results.append(res) return results - # WTF - def search_books(self, query, filters=None, max_results=10): - return self._find_some_books(max_results=max_results) - - def search_everywhere(self, searched, query_terms=None): - return [] - - def hint_tags(self, query, pdcounter=True, prefix=True): - return Tag.objects.exclude(category='set').order_by('?')[:randint(1, 10)] - - def hint_books(self, prefix): - return Book.objects.order_by('?')[:randint(1, 10)]