server/test/unittest_fti.py
changeset 6366 1806148d6ce8
parent 6340 470d8e828fda
child 6436 275e9f402ccc
equal deleted inserted replaced
6333:e3994fcc21c3 6366:1806148d6ce8
    10 class PostgresFTITC(CubicWebTC):
    10 class PostgresFTITC(CubicWebTC):
    11     config = ApptestConfiguration('data', sourcefile='sources_fti')
    11     config = ApptestConfiguration('data', sourcefile='sources_fti')
    12 
    12 
    13     def setUp(self):
    13     def setUp(self):
    14         if not socket.gethostname().endswith('.logilab.fr'):
    14         if not socket.gethostname().endswith('.logilab.fr'):
    15             self.skip('XXX require logilab configuration')
    15             self.skipTest('XXX require logilab configuration')
    16         super(PostgresFTITC, self).setUp()
    16         super(PostgresFTITC, self).setUp()
    17 
    17 
    18     def test_occurence_count(self):
    18     def test_occurence_count(self):
    19         req = self.request()
    19         req = self.request()
    20         c1 = req.create_entity('Card', title=u'c1',
    20         c1 = req.create_entity('Card', title=u'c1',
    22         c2 = req.create_entity('Card', title=u'c3',
    22         c2 = req.create_entity('Card', title=u'c3',
    23                                content=u'cubicweb')
    23                                content=u'cubicweb')
    24         c3 = req.create_entity('Card', title=u'c2',
    24         c3 = req.create_entity('Card', title=u'c2',
    25                                content=u'cubicweb cubicweb')
    25                                content=u'cubicweb cubicweb')
    26         self.commit()
    26         self.commit()
    27         self.assertEquals(req.execute('Card X ORDERBY FTIRANK(X) DESC WHERE X has_text "cubicweb"').rows,
    27         self.assertEqual(req.execute('Card X ORDERBY FTIRANK(X) DESC WHERE X has_text "cubicweb"').rows,
    28                           [[c1.eid], [c3.eid], [c2.eid]])
    28                           [[c1.eid], [c3.eid], [c2.eid]])
    29 
    29 
    30 
    30 
    31     def test_attr_weight(self):
    31     def test_attr_weight(self):
    32         class CardIFTIndexableAdapter(IFTIndexableAdapter):
    32         class CardIFTIndexableAdapter(IFTIndexableAdapter):
    39             c2 = req.create_entity('Card', title=u'c2',
    39             c2 = req.create_entity('Card', title=u'c2',
    40                                    content=u'cubicweb cubicweb')
    40                                    content=u'cubicweb cubicweb')
    41             c3 = req.create_entity('Card', title=u'cubicweb',
    41             c3 = req.create_entity('Card', title=u'cubicweb',
    42                                    content=u'autre chose')
    42                                    content=u'autre chose')
    43             self.commit()
    43             self.commit()
    44             self.assertEquals(req.execute('Card X ORDERBY FTIRANK(X) DESC WHERE X has_text "cubicweb"').rows,
    44             self.assertEqual(req.execute('Card X ORDERBY FTIRANK(X) DESC WHERE X has_text "cubicweb"').rows,
    45                               [[c3.eid], [c1.eid], [c2.eid]])
    45                               [[c3.eid], [c1.eid], [c2.eid]])
    46 
    46 
    47 
    47 
    48     def test_entity_weight(self):
    48     def test_entity_weight(self):
    49         class PersonneIFTIndexableAdapter(IFTIndexableAdapter):
    49         class PersonneIFTIndexableAdapter(IFTIndexableAdapter):
    53             req = self.request()
    53             req = self.request()
    54             c1 = req.create_entity('Personne', nom=u'c1', prenom=u'cubicweb')
    54             c1 = req.create_entity('Personne', nom=u'c1', prenom=u'cubicweb')
    55             c2 = req.create_entity('Comment', content=u'cubicweb cubicweb', comments=c1)
    55             c2 = req.create_entity('Comment', content=u'cubicweb cubicweb', comments=c1)
    56             c3 = req.create_entity('Comment', content=u'cubicweb cubicweb cubicweb', comments=c1)
    56             c3 = req.create_entity('Comment', content=u'cubicweb cubicweb cubicweb', comments=c1)
    57             self.commit()
    57             self.commit()
    58             self.assertEquals(req.execute('Any X ORDERBY FTIRANK(X) DESC WHERE X has_text "cubicweb"').rows,
    58             self.assertEqual(req.execute('Any X ORDERBY FTIRANK(X) DESC WHERE X has_text "cubicweb"').rows,
    59                               [[c1.eid], [c3.eid], [c2.eid]])
    59                               [[c1.eid], [c3.eid], [c2.eid]])