1 # This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later.
2 # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
4 from unittest.mock import Mock
5 from catalogue.models import Book, Tag
6 from random import randint, choice
11 Search mock for development without setting up Solr.
13 Instead of connecting to an actual search server, it returns
14 some random results for any query.
16 class MockIndex(Mock):
17 def analyze(*args, **kwargs):
23 def _find_some_books(query_terms=None, max_results=20):
24 from .index import SearchResult
26 qs = Book.objects.filter(findable=True).order_by('?')
28 for book in qs[:randint(1, max_results)]:
30 'score': randint(0, 100),
32 'published_date': randint(1000, 1920),
34 res = SearchResult(doc, how_found='mock', query_terms=query_terms)
38 def search_everywhere(self, searched, query_terms=None):