- inheriting covers after parents,
[wolnelektury.git] / apps / search / tests / index.py
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
6 from os import path
7 import tempfile
8 from catalogue import models
9 from search import Search, SearchResult
10
11
12 @override_settings(
13     SEARCH_INDEX = tempfile.mkdtemp(prefix='djangotest_search_'),
14 )
15 class BookSearchTests(WLTestCase):
16     def setUp(self):
17         WLTestCase.setUp(self)
18
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()
23
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
28
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
33
34     def test_search_perfect_parts(self):
35         books = self.search.search_perfect_parts("Jakoż hamować")
36         assert len(books) == 2
37         for b in books:
38             b.book_id == self.book.id
39         a = SearchResult.aggregate(books)
40         # just one fragment hit.
41         assert len(a[0].hits) == 1
42
43     def test_search_perfect_author_title(self):
44         books = self.search.search_perfect_book("szarzyński anusie")
45         assert books == []
46
47         books = self.search.search_book("szarzyński anusie")
48         assert len(books) == 1
49
50         books = self.search.search_book("szarzyński fraszka")
51         assert len(books) == 1
52
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]
56
57         books = self.search.search_everywhere("szarzyński narcyz")
58         print 'szarzyński narcyz %s' % [b.hits for b in books]
59
60         books = self.search.search_everywhere("anusie narcyz")
61         print 'anusie narcyz %s' % [b.hits for b in books]
62
63         # theme content cross
64         books = self.search.search_everywhere("wzrok  boginie")
65         print 'wzrok boginie %s' % [b.hits for b in books]
66
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]