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
5 from lucene import PolishAnalyzer, Version
8 from catalogue import models
9 from search import Search, SearchResult
13 SEARCH_INDEX = tempfile.mkdtemp(prefix='djangotest_search_'),
15 class BookSearchTests(WLTestCase):
17 WLTestCase.setUp(self)
19 txt = path.join(path.dirname(__file__), 'files/fraszka-do-anusie.xml')
20 with self.settings(NO_SEARCH_INDEX=False):
21 self.book = models.Book.from_xml_file(txt)
22 self.search = Search()
24 def test_search_perfect_book_author(self):
25 books = self.search.search_perfect_book("sęp szarzyński")
26 assert len(books) == 1
27 assert books[0].book_id == self.book.id
29 def test_search_perfect_book_title(self):
30 books = self.search.search_perfect_book("fraszka anusie")
31 assert len(books) == 1
32 assert books[0].book_id == self.book.id
34 def test_search_perfect_parts(self):
35 books = self.search.search_perfect_parts("Jakoż hamować")
36 assert len(books) == 2
38 b.book_id == self.book.id
39 a = SearchResult.aggregate(books)
40 # just one fragment hit.
41 assert len(a[0].hits) == 1
43 def test_search_perfect_author_title(self):
44 books = self.search.search_perfect_book("szarzyński anusie")
47 books = self.search.search_book("szarzyński anusie")
48 assert len(books) == 1
50 books = self.search.search_book("szarzyński fraszka")
51 assert len(books) == 1
53 def test_search_everywhere(self):
54 books = self.search.search_everywhere("szarzyński kochanek")
55 print 'szarzyński kochanek %s' % [b.hits for b in books]
57 books = self.search.search_everywhere("szarzyński narcyz")
58 print 'szarzyński narcyz %s' % [b.hits for b in books]
60 books = self.search.search_everywhere("anusie narcyz")
61 print 'anusie narcyz %s' % [b.hits for b in books]
64 books = self.search.search_everywhere("wzrok boginie")
65 print 'wzrok boginie %s' % [b.hits for b in books]
67 books = self.search.search_everywhere("anusie płynęły zdroje")
68 print 'anusie płynęły zdroje %s' % [b.hits for b in books]