1 # -*- coding: utf-8 -*-
2 from django.conf import settings
3 from django.test.utils import override_settings
4 from catalogue.test_utils import WLTestCase, get_fixture
7 from catalogue.models import Book, Tag
8 from search import Index, Search, SearchResult
14 SEARCH_INDEX = tempfile.mkdtemp(prefix='djangotest_search_'),
16 class BookSearchTests(WLTestCase):
18 WLTestCase.setUp(self)
21 index.index.delete_all()
24 with self.settings(NO_SEARCH_INDEX=False):
25 self.do_doktora = Book.from_xml_file(
26 get_fixture('do-doktora.xml', opds))
27 self.do_anusie = Book.from_xml_file(
28 get_fixture('fraszka-do-anusie.xml', catalogue))
30 self.search = Search()
32 def test_search_perfect_book_author(self):
33 books = self.search.search_books(self.search.index.query(authors=u"sęp szarzyński"))
34 assert len(books) == 1
35 assert books[0].book_id == self.book.id
37 def test_search_perfect_book_title(self):
38 books = self.search.search_books(self.search.index.query(u"fraszka anusie"))
39 assert len(books) == 1
40 assert books[0].book_id == self.book.id
42 def test_search_perfect_parts(self):
43 books = self.search.search_phrase(u"Jakoż hamować")
44 assert len(books) == 2
46 b.book_id == self.book.id
47 a = SearchResult.aggregate(books)
48 # just one fragment hit.
49 assert len(a[0].hits) == 1
51 def test_search_perfect_author_title(self):
52 books = self.search.search_books(self.search.index.query(authors=u"szarzyński anusie"))