Make verse numbers, footnote anchors, themes, dynamic inserts unselectable. Fixes...
[wolnelektury.git] / src / search / mock_search.py
index 253c277..118078f 100644 (file)
@@ -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.
 #
 # 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
 
 from catalogue.models import Book, Tag
 from random import randint, choice
 
@@ -21,12 +20,10 @@ class Search(Mock):
     index = MockIndex()
 
     @staticmethod
     index = MockIndex()
 
     @staticmethod
-    def _find_some_books(snippets=False, query_terms=None, max_results=20):
+    def _find_some_books(query_terms=None, max_results=20):
         from .index import SearchResult
 
         from .index import SearchResult
 
-        qs = Book.objects.order_by('?')
-        if snippets:
-            qs = qs.exclude(fragments=None)
+        qs = Book.objects.filter(findable=True).order_by('?')
         results = []
         for book in qs[:randint(1, max_results)]:
             doc = {
         results = []
         for book in qs[:randint(1, max_results)]:
             doc = {
@@ -34,39 +31,10 @@ class Search(Mock):
                 'book_id': book.pk,
                 'published_date': randint(1000, 1920),
                 }
                 'book_id': book.pk,
                 'published_date': randint(1000, 1920),
                 }
-            if snippets:
-                fragment = book.fragments.order_by('?')[0]
-                doc.update({
-                    'header_type': choice(['strofa', 'akap']),
-                    'header_index': randint(100, 200),
-                    'header_span': randint(100, 200),
-                    'fragment_anchor': fragment.anchor,
-                    'snippets_position': randint(100, 200),
-                    'snippets_length': randint(100, 200),
-                    'snippets_revision': randint(1, 100),
-                    'themes_pl': fragment.tags.filter(category='theme'),
-                })
             res = SearchResult(doc, how_found='mock', query_terms=query_terms)
             res = SearchResult(doc, how_found='mock', query_terms=query_terms)
-            if snippets:
-                res.snippets = [fragment.short_text]
             results.append(res)
         return results
 
             results.append(res)
         return results
 
-    def search_phrase(self, searched, field='text', book=False,
-            filters=None, snippets=False):
-        return self._find_some_books(snippets)
-
-    def search_some(self, searched, fields, book=True, filters=None, snippets=True, query_terms=None):
-        return self._find_some_books(snippets, query_terms)
-
-    def search_books(self, query, filters=None, max_results=10):
-        return self._find_some_books(snippets, max_results=max_results)
-
     def search_everywhere(self, searched, query_terms=None):
         return []
 
     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)]