Some refactoring & documentation changes in search.
[wolnelektury.git] / apps / search / tests / index.py
1 from __future__ import with_statement
2
3 from search import Index, Search, IndexStore
4 from catalogue import models
5 from catalogue.test_utils import WLTestCase
6 from lucene import PolishAnalyzer, Version
7 #from nose.tools import raises
8 from os import path
9
10
11
12
13 class BookSearchTests(WLTestCase):
14     def setUp(self):
15         WLTestCase.setUp(self)
16
17         txt = path.join(path.dirname(__file__), 'files/fraszka-do-anusie.xml')
18         self.book = models.Book.from_xml_file(txt)
19
20         search = Index() #PolishAnalyzer(Version.LUCENE_34))
21         with search:
22             search.index_book(self.book)
23         print "index: %s" % search
24
25     def test_search(self):
26         search = Search()
27         bks,_= search.search("wolne")
28         self.assertEqual(len(bks), 1)
29         self.assertEqual(bks[0].id, 1)
30         
31         bks,_= search.search("technical_editors: sutkowska")
32         self.assertEqual(len(bks), 1)
33         self.assertEqual(bks[0].id, 1)
34