1 # -*- coding: utf-8 -*-
 
   2 # This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later.
 
   3 # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
 
   6 from catalogue.models import Book, Tag
 
   7 from random import randint, choice
 
  12     Search mock for development without setting up Solr.
 
  14     Instead of connecting to an actual search server, it returns
 
  15     some random results for any query.
 
  17     class MockIndex(Mock):
 
  18         def analyze(*args, **kwargs):
 
  24     def _find_some_books(query_terms=None, max_results=20):
 
  25         from .index import SearchResult
 
  27         qs = Book.objects.order_by('?')
 
  29         for book in qs[:randint(1, max_results)]:
 
  31                 'score': randint(0, 100),
 
  33                 'published_date': randint(1000, 1920),
 
  35             res = SearchResult(doc, how_found='mock', query_terms=query_terms)
 
  39     def search_everywhere(self, searched, query_terms=None):