OPDS advanced search
[wolnelektury.git] / apps / search / tests / index.py
1 from __future__ import with_statement
2
3 from search import Index, Search
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 class BookSearchTests(WLTestCase):
12     def setUp(self):
13         WLTestCase.setUp(self)
14
15         txt = path.join(path.dirname(__file__), 'files/fraszka-do-anusie.xml')
16         self.book = models.Book.from_xml_file(txt)
17
18         search = Index() #PolishAnalyzer(Version.LUCENE_34))
19         with search:
20             search.index_book(self.book)
21         print "index: %s" % search
22
23     def test_search(self):
24         search = Search()
25         bks,_= search.search("wolne")
26         self.assertEqual(len(bks), 1)
27         self.assertEqual(bks[0].id, 1)
28         
29         bks,_= search.search("technical_editors: sutkowska")
30         self.assertEqual(len(bks), 1)
31         self.assertEqual(bks[0].id, 1)
32