__init__.py
103 lines
| 2.9 KiB
| text/x-python
|
PythonLexer
r1 | # -*- coding: utf-8 -*- | |||
r3363 | # Copyright (C) 2012-2019 RhodeCode GmbH | |||
r1 | # | |||
# This program is free software: you can redistribute it and/or modify | ||||
# it under the terms of the GNU Affero General Public License, version 3 | ||||
# (only), as published by the Free Software Foundation. | ||||
# | ||||
# This program 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 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/>. | ||||
# | ||||
# This program is dual-licensed. If you wish to learn more about the | ||||
# RhodeCode Enterprise Edition, including its added features, Support services, | ||||
# and proprietary license terms, please see https://rhodecode.com/licenses/ | ||||
""" | ||||
Index schema for RhodeCode | ||||
""" | ||||
import importlib | ||||
import logging | ||||
r3319 | from rhodecode.lib.index.search_utils import normalize_text_for_matching | |||
r1 | log = logging.getLogger(__name__) | |||
# leave defaults for backward compat | ||||
default_searcher = 'rhodecode.lib.index.whoosh' | ||||
default_location = '%(here)s/data/index' | ||||
r3319 | ES_VERSION_2 = '2' | |||
ES_VERSION_6 = '6' | ||||
# for legacy reasons we keep 2 compat as default | ||||
DEFAULT_ES_VERSION = ES_VERSION_2 | ||||
r1 | ||||
r3319 | from rhodecode_tools.lib.fts_index.elasticsearch_engine_6 import \ | |||
ES_CONFIG # pragma: no cover | ||||
class BaseSearcher(object): | ||||
r1684 | query_lang_doc = '' | |||
r3319 | es_version = None | |||
name = None | ||||
r1684 | ||||
r1 | def __init__(self): | |||
pass | ||||
def cleanup(self): | ||||
pass | ||||
r3441 | def search(self, query, document_type, search_user, | |||
repo_name=None, repo_group_name=None, | ||||
r1411 | raise_on_exc=True): | |||
r1 | raise Exception('NotImplemented') | |||
r3319 | @staticmethod | |||
def query_to_mark(query, default_field=None): | ||||
""" | ||||
Formats the query to mark token for jquery.mark.js highlighting. ES could | ||||
have a different format optionally. | ||||
r1411 | ||||
r3319 | :param default_field: | |||
:param query: | ||||
""" | ||||
return ' '.join(normalize_text_for_matching(query).split()) | ||||
@property | ||||
def is_es_6(self): | ||||
return self.es_version == ES_VERSION_6 | ||||
def get_handlers(self): | ||||
return {} | ||||
r3442 | @staticmethod | |||
def extract_search_tags(query): | ||||
return [] | ||||
r3319 | ||||
def search_config(config, prefix='search.'): | ||||
r1 | _config = {} | |||
for key in config.keys(): | ||||
if key.startswith(prefix): | ||||
_config[key[len(prefix):]] = config[key] | ||||
r3319 | return _config | |||
def searcher_from_config(config, prefix='search.'): | ||||
_config = search_config(config, prefix) | ||||
r1 | ||||
if 'location' not in _config: | ||||
_config['location'] = default_location | ||||
r3319 | if 'es_version' not in _config: | |||
# use old legacy ES version set to 2 | ||||
_config['es_version'] = '2' | ||||
r1 | imported = importlib.import_module(_config.get('module', default_searcher)) | |||
r3319 | searcher = imported.Searcher(config=_config) | |||
r1 | return searcher | |||