<commit_before># -*- coding: utf-8 -*-


# Etalage-Passim -- Customization of Etalage for Passim
# By: <NAME> <<EMAIL>>
#
# Copyright (C) 2012 Easter-eggs
# http://gitorious.org/passim/etalage-passim
#
# This file is part of Etalage-Passim.
#
# Etalage-Passim is free software; you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# Etalage-Passim is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.


import itertools

from biryani import strings

from etalage import conv, pois, ramdb


class Poi(pois.Poi):
    ids_by_coverage = {}  # class attribute
    ids_by_schema_name = {}  # class attribute
    ids_by_transport_type = {}  # class attribute
    weight_by_coverage = {
        u'Départementale': 1,
        u'Locale': 0,
        u'Nationale': 3,
        u'Régionale': 2,
        }

    @classmethod
    def clear_indexes(cls):
        super(Poi, cls).clear_indexes()

        cls.ids_by_coverage.clear()
        cls.ids_by_schema_name.clear()
        cls.ids_by_transport_type.clear()

    @classmethod
    def extract_non_territorial_search_data(cls, ctx, data):
        return dict(
            coverages = data['coverages'],
            schemas_name = data['schemas_name'],
            term = data['term'],
            transport_types = data['transport_types'],
            )

    @classmethod
    def extract_search_inputs_from_params(cls, ctx, params):
        return dict(
            coverages = params.getall('coverage'),
            schemas_name = params.getall('schema'),
            filter = params.get('filter'),
            term = params.get('term'),
            territory = params.get('territory'),
            transport_types = params.getall('transport_type'),
            )

    def index(self, indexed_poi_id):
        super(Poi, self).index(indexed_poi_id)

        if self.schema_name == 'OffreTransport':
            if not self.competence_territories_id:
                france_id = ramdb.territory_id_by_kind_code[(u'Country', u'FR')]
                self.competence_territories_id = set([france_id])
                self.ids_by_competence_territory_id.setdefault(france_id, set()).add(indexed_poi_id)

            for field in self.fields:<commit_msg>Don't add France to competence territories when root POI has competence territories.<commit_after># -*- coding: utf-8 -*-


# Etalage-Passim -- Customization of Etalage for Passim
# By: <NAME> <<EMAIL>>
#
# Copyright (C) 2012 Easter-eggs
# http://gitorious.org/passim/etalage-passim
#
# This file is part of Etalage-Passim.
#
# Etalage-Passim is free software; you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# Etalage-Passim is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.


import itertools

from biryani import strings

from etalage import conv, pois, ramdb


class Poi(pois.Poi):
    ids_by_coverage = {}  # class attribute
    ids_by_schema_name = {}  # class attribute
    ids_by_transport_type = {}  # class attribute
    weight_by_coverage = {
        u'Départementale': 1,
        u'Locale': 0,
        u'Nationale': 3,
        u'Régionale': 2,
        }

    @classmethod
    def clear_indexes(cls):
        super(Poi, cls).clear_indexes()

        cls.ids_by_coverage.clear()
        cls.ids_by_schema_name.clear()
        cls.ids_by_transport_type.clear()

    @classmethod
    def extract_non_territorial_search_data(cls, ctx, data):
        return dict(
            coverages = data['coverages'],
            schemas_name = data['schemas_name'],
            term = data['term'],
            transport_types = data['transport_types'],
            )

    @classmethod
    def extract_search_inputs_from_params(cls, ctx, params):
        return dict(
            coverages = params.getall('coverage'),
            schemas_name = params.getall('schema'),
            filter = params.get('filter'),
            term = params.get('term'),
            territory = params.get('territory'),
            transport_types = params.getall('transport_type'),
            )

    def index(self, indexed_poi_id):
        super(Poi, self).index(indexed_poi_id)

        if self.schema_name == 'OffreTransport':
            if not self.competence_territories_id and not self.instance_by_id[indexed_poi_id].competence_territories_id:
                france_id = ramdb.territory_id_by_kind_code[(u'Country', u'FR')]
                self.competence_territories_id = set([france_id])
                self.ids_by_competence_territory_id.setdefault(france_id, set()).add(indexed_poi_id)

            for field in self.fields:
{'fraction_non_alphanumeric': 0.0979858464888405, 'fraction_numerical': 0.0036291054255126113, 'mean_word_length': 2.8545454545454545, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2446548', 'n_tokens_mistral': 1709, 'n_tokens_neox': 1644, 'n_words': 451}