def setup_method(self, _): import transaction from sqlalchemy import func from geoalchemy2 import WKTElement from c2cgeoportal_commons.models import DBSession from c2cgeoportal_commons.models.main import FullTextSearch, Role, Interface from c2cgeoportal_commons.models.static import User user1 = User(username="******", password="******") role1 = Role(name="__test_role1", description="__test_role1") user1.role_name = role1.name user2 = User(username="******", password="******") role2 = Role(name="__test_role2", description="__test_role2") user2.role_name = role2.name entry1 = FullTextSearch() entry1.label = "label1" entry1.layer_name = "layer1" entry1.ts = func.to_tsvector("french", "soleil travail") entry1.the_geom = WKTElement("POINT(-90 -45)", 21781) entry1.public = True entry2 = FullTextSearch() entry2.label = "label2" entry2.layer_name = "layer2" entry2.ts = func.to_tsvector("french", "pluie semaine") entry2.the_geom = WKTElement("POINT(-90 -45)", 21781) entry2.public = False entry3 = FullTextSearch() entry3.label = "label3" entry3.layer_name = "layer3" entry3.ts = func.to_tsvector("french", "vent neige") entry3.the_geom = WKTElement("POINT(-90 -45)", 21781) entry3.public = False entry3.role = role2 entry4 = FullTextSearch() entry4.label = "label4" entry4.layer_name = "layer1" entry4.ts = func.to_tsvector("french", "soleil travail") entry4.the_geom = WKTElement("POINT(-90 -45)", 21781) entry4.public = True entry5 = FullTextSearch() entry5.label = "label5" entry5.ts = func.to_tsvector("french", "params") entry5.public = True entry5.params = {"floor": 5} entry5.actions = [{"action": "add_layer", "data": "layer1"}] entry6 = FullTextSearch() entry6.label = "label6" entry6.ts = func.to_tsvector("french", "params") entry6.interface = Interface("main") entry6.public = True DBSession.add_all([user1, user2, role1, role2, entry1, entry2, entry3, entry4, entry5, entry6]) transaction.commit()
def _add_fts( self, item: "c2cgeoportal_commons.models.main.TreeItem", interface: "c2cgeoportal_commons.models.main.Interface", action: str, role: Optional["c2cgeoportal_commons.models.main.Role"], ) -> None: from c2cgeoportal_commons.models.main import FullTextSearch # pylint: disable=import-outside-toplevel key = ( item.name if self.options.name else item.id, interface.id, role.id if role is not None else None, ) if key not in self.imported: self.imported.add(key) for lang in self.languages: fts = FullTextSearch() fts.label = self._[lang].gettext(item.name) fts.role = role fts.interface = interface fts.lang = lang fts.public = role is None fts.ts = func.to_tsvector( self.fts_languages[lang], " ".join( [self.fts_normalizer(self._[lang].gettext(item.name))] + [v.strip() for m in item.get_metadatas("searchAlias") for v in m.value.split(",")] ), ) fts.actions = [{"action": action, "data": item.name}] fts.from_theme = True self.session.add(fts)
def test_delete_cascade_to_tsearch(self, dbsession): from c2cgeoportal_commons.models.main import Interface, FullTextSearch from sqlalchemy import func interface = Interface("desktop", "Desktop interface") interface_id = interface.id fts = FullTextSearch() fts.label = "Text to search" fts.interface = interface fts.ts = func.to_tsvector("french", fts.label) dbsession.add(fts) dbsession.flush() dbsession.delete(interface) dbsession.flush() assert ( 0 == dbsession.query(FullTextSearch).filter(FullTextSearch.interface_id == interface_id).count() )
def _add_fts(self, item, interface, action, role): from c2cgeoportal_commons.models.main import FullTextSearch key = (item.name if self.options.name else item.id, interface.id, role.id if role is not None else None) if key not in self.imported: self.imported.add(key) for lang in self.languages: fts = FullTextSearch() fts.label = self._unicode_str(self._[lang].gettext(item.name)) fts.role = role fts.interface = interface fts.lang = lang fts.public = role is None fts.ts = func.to_tsvector(self.fts_languages[lang], fts.label) fts.actions = [{ "action": action, "data": item.name, }] fts.from_theme = True self.session.add(fts)
def _add_fts(self, item, interface, action, role): from c2cgeoportal_commons.models.main import FullTextSearch key = ( item.name if self.options.name else item.id, interface.id, role.id if role is not None else None ) if key not in self.imported: self.imported.add(key) for lang in self.languages: fts = FullTextSearch() fts.label = self._[lang].gettext(item.name) fts.role = role fts.interface = interface fts.lang = lang fts.public = role is None fts.ts = func.to_tsvector(self.fts_languages[lang], fts.label) fts.actions = [{ "action": action, "data": item.name, }] fts.from_theme = True self.session.add(fts)
def setup_method(self, _): import transaction from sqlalchemy import func from geoalchemy2 import WKTElement from c2cgeoportal_commons.models import DBSession from c2cgeoportal_commons.models.main import FullTextSearch, Role, Interface from c2cgeoportal_commons.models.static import User role1 = Role(name="__test_role1", description="__test_role1") user1 = User(username="******", password="******", settings_role=role1, roles=[role1]) role2 = Role(name="__test_role2", description="__test_role2") user2 = User(username="******", password="******", settings_role=role2, roles=[role2]) entry1 = FullTextSearch() entry1.label = "label1" entry1.layer_name = "layer1" entry1.ts = func.to_tsvector("french", "soleil travail") entry1.the_geom = WKTElement("POINT(-90 -45)", 21781) entry1.public = True entry2 = FullTextSearch() entry2.label = "label2" entry2.layer_name = "layer2" entry2.ts = func.to_tsvector("french", "pluie semaine") entry2.the_geom = WKTElement("POINT(-90 -45)", 21781) entry2.public = False entry3 = FullTextSearch() entry3.label = "label3" entry3.layer_name = "layer3" entry3.ts = func.to_tsvector("french", "vent neige") entry3.the_geom = WKTElement("POINT(-90 -45)", 21781) entry3.public = False entry3.role = role2 entry4 = FullTextSearch() entry4.label = "label4" entry4.layer_name = "layer1" entry4.ts = func.to_tsvector("french", "soleil travail") entry4.the_geom = WKTElement("POINT(-90 -45)", 21781) entry4.public = True entry5 = FullTextSearch() entry5.label = "label5" entry5.ts = func.to_tsvector("french", "lausanne") entry5.public = True entry5.params = {"floor": 5} entry5.actions = [{"action": "add_layer", "data": "layer1"}] entry6 = FullTextSearch() entry6.label = "label6" entry6.ts = func.to_tsvector("french", "lausanne") entry6.interface = Interface("main") entry6.public = True # To test the similarity ranking method entry7 = FullTextSearch() entry7.label = "A 7 simi" entry7.ts = func.to_tsvector("french", "A 7 simi") entry7.public = True entry70 = FullTextSearch() entry70.label = "A 70 simi" entry70.ts = func.to_tsvector("french", "A 70 simi") entry70.public = True entry71 = FullTextSearch() entry71.label = "A 71 simi" entry71.ts = func.to_tsvector("french", "A 71 simi") entry71.public = True DBSession.add_all([ user1, user2, role1, role2, entry1, entry2, entry3, entry4, entry5, entry6, entry71, entry70, entry7, ]) transaction.commit()