5 from cubicweb.devtools import ApptestConfiguration |
5 from cubicweb.devtools import ApptestConfiguration |
6 from cubicweb.devtools.testlib import CubicWebTC |
6 from cubicweb.devtools.testlib import CubicWebTC |
7 from cubicweb.selectors import is_instance |
7 from cubicweb.selectors import is_instance |
8 from cubicweb.entities.adapters import IFTIndexableAdapter |
8 from cubicweb.entities.adapters import IFTIndexableAdapter |
9 |
9 |
|
10 AT_LOGILAB = socket.gethostname().endswith('.logilab.fr') |
|
11 |
|
12 from logilab.common.testlib import SkipTest |
|
13 |
|
14 |
10 class PostgresFTITC(CubicWebTC): |
15 class PostgresFTITC(CubicWebTC): |
11 config = ApptestConfiguration('data', sourcefile='sources_fti') |
16 config = ApptestConfiguration('data', sourcefile='sources_fti') |
12 |
17 |
13 def setUp(self): |
18 @classmethod |
14 if not socket.gethostname().endswith('.logilab.fr'): |
19 def setUpClass(cls): |
15 self.skipTest('XXX require logilab configuration') |
20 if not AT_LOGILAB: |
16 super(PostgresFTITC, self).setUp() |
21 raise SkipTest('XXX %s: require logilab configuration' % cls.__name__) |
17 |
22 |
18 def test_occurence_count(self): |
23 def test_occurence_count(self): |
19 req = self.request() |
24 req = self.request() |
20 c1 = req.create_entity('Card', title=u'c1', |
25 c1 = req.create_entity('Card', title=u'c1', |
21 content=u'cubicweb cubicweb cubicweb') |
26 content=u'cubicweb cubicweb cubicweb') |
42 content=u'autre chose') |
47 content=u'autre chose') |
43 self.commit() |
48 self.commit() |
44 self.assertEqual(req.execute('Card X ORDERBY FTIRANK(X) DESC WHERE X has_text "cubicweb"').rows, |
49 self.assertEqual(req.execute('Card X ORDERBY FTIRANK(X) DESC WHERE X has_text "cubicweb"').rows, |
45 [[c3.eid], [c1.eid], [c2.eid]]) |
50 [[c3.eid], [c1.eid], [c2.eid]]) |
46 |
51 |
47 |
|
48 def test_entity_weight(self): |
52 def test_entity_weight(self): |
49 class PersonneIFTIndexableAdapter(IFTIndexableAdapter): |
53 class PersonneIFTIndexableAdapter(IFTIndexableAdapter): |
50 __select__ = is_instance('Personne') |
54 __select__ = is_instance('Personne') |
51 entity_weight = 2.0 |
55 entity_weight = 2.0 |
52 with self.temporary_appobjects(PersonneIFTIndexableAdapter): |
56 with self.temporary_appobjects(PersonneIFTIndexableAdapter): |
56 c3 = req.create_entity('Comment', content=u'cubicweb cubicweb cubicweb', comments=c1) |
60 c3 = req.create_entity('Comment', content=u'cubicweb cubicweb cubicweb', comments=c1) |
57 self.commit() |
61 self.commit() |
58 self.assertEqual(req.execute('Any X ORDERBY FTIRANK(X) DESC WHERE X has_text "cubicweb"').rows, |
62 self.assertEqual(req.execute('Any X ORDERBY FTIRANK(X) DESC WHERE X has_text "cubicweb"').rows, |
59 [[c1.eid], [c3.eid], [c2.eid]]) |
63 [[c1.eid], [c3.eid], [c2.eid]]) |
60 |
64 |
|
65 |
61 if __name__ == '__main__': |
66 if __name__ == '__main__': |
62 from logilab.common.testlib import unittest_main |
67 from logilab.common.testlib import unittest_main |
63 unittest_main() |
68 unittest_main() |