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):
22 def search_words(self, words, fields, required=None, book=True, picture=False):
23 from .index import SearchResult
29 qs = Book.objects.filter(findable=True).order_by('?')
31 for book in qs[:randint(1, max_results)]:
33 'score': randint(0, 100),
35 'published_date': randint(1000, 1920),
37 res = SearchResult(doc, how_found='mock', query_terms=words)