server/test/unittest_fti.py
changeset 5768 1e73a466aa69
child 5877 0c7b7b76a84f
equal deleted inserted replaced
5766:c397819f2482 5768:1e73a466aa69
       
     1 from __future__ import with_statement
       
     2 
       
     3 from cubicweb.devtools import ApptestConfiguration
       
     4 from cubicweb.devtools.testlib import CubicWebTC
       
     5 from cubicweb.selectors import implements
       
     6 from cubicweb.entities.adapters import IFTIndexableAdapter
       
     7 
       
     8 class PostgresFTITC(CubicWebTC):
       
     9     config = ApptestConfiguration('data', sourcefile='sources_fti')
       
    10 
       
    11     def test_occurence_count(self):
       
    12         req = self.request()
       
    13         c1 = req.create_entity('Card', title=u'c1',
       
    14                                content=u'cubicweb cubicweb cubicweb')
       
    15         c2 = req.create_entity('Card', title=u'c3',
       
    16                                content=u'cubicweb')
       
    17         c3 = req.create_entity('Card', title=u'c2',
       
    18                                content=u'cubicweb cubicweb')
       
    19         self.commit()
       
    20         self.assertEquals(req.execute('Card X ORDERBY FTIRANK(X) DESC WHERE X has_text "cubicweb"').rows,
       
    21                           [[c1.eid], [c3.eid], [c2.eid]])
       
    22 
       
    23 
       
    24     def test_attr_weight(self):
       
    25         class CardIFTIndexableAdapter(IFTIndexableAdapter):
       
    26             __select__ = implements('Card')
       
    27             attr_weight = {'title': 'A'}
       
    28         with self.temporary_appobjects(CardIFTIndexableAdapter):
       
    29             req = self.request()
       
    30             c1 = req.create_entity('Card', title=u'c1',
       
    31                                    content=u'cubicweb cubicweb cubicweb')
       
    32             c2 = req.create_entity('Card', title=u'c2',
       
    33                                    content=u'cubicweb cubicweb')
       
    34             c3 = req.create_entity('Card', title=u'cubicweb',
       
    35                                    content=u'autre chose')
       
    36             self.commit()
       
    37             self.assertEquals(req.execute('Card X ORDERBY FTIRANK(X) DESC WHERE X has_text "cubicweb"').rows,
       
    38                               [[c3.eid], [c1.eid], [c2.eid]])
       
    39 
       
    40 
       
    41     def test_entity_weight(self):
       
    42         class PersonneIFTIndexableAdapter(IFTIndexableAdapter):
       
    43             __select__ = implements('Personne')
       
    44             entity_weight = 2.0
       
    45         with self.temporary_appobjects(PersonneIFTIndexableAdapter):
       
    46             req = self.request()
       
    47             c1 = req.create_entity('Personne', nom=u'c1', prenom=u'cubicweb')
       
    48             c2 = req.create_entity('Comment', content=u'cubicweb cubicweb', comments=c1)
       
    49             c3 = req.create_entity('Comment', content=u'cubicweb cubicweb cubicweb', comments=c1)
       
    50             self.commit()
       
    51             self.assertEquals(req.execute('Any X ORDERBY FTIRANK(X) DESC WHERE X has_text "cubicweb"').rows,
       
    52                               [[c1.eid], [c3.eid], [c2.eid]])