##// END OF EJS Templates
admin: store client in ops error to track excessive user details triggering this error....
admin: store client in ops error to track excessive user details triggering this error. - additionally add some sort of rate limitter to prevent flooding this view

File last commit:

r3319:b8fd1d7a default
r3324:8ec127fe default
Show More
__init__.py
98 lines | 2.8 KiB | text/x-python | PythonLexer
project: added all source files and assets
r1 # -*- coding: utf-8 -*-
release: update copyright year to 2018
r2487 # Copyright (C) 2012-2018 RhodeCode GmbH
project: added all source files and assets
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
dan
search: add support for elastic search 6...
r3319 from rhodecode.lib.index.search_utils import normalize_text_for_matching
project: added all source files and assets
r1 log = logging.getLogger(__name__)
# leave defaults for backward compat
default_searcher = 'rhodecode.lib.index.whoosh'
default_location = '%(here)s/data/index'
dan
search: add support for elastic search 6...
r3319 ES_VERSION_2 = '2'
ES_VERSION_6 = '6'
# for legacy reasons we keep 2 compat as default
DEFAULT_ES_VERSION = ES_VERSION_2
project: added all source files and assets
r1
dan
search: add support for elastic search 6...
r3319 from rhodecode_tools.lib.fts_index.elasticsearch_engine_6 import \
ES_CONFIG # pragma: no cover
class BaseSearcher(object):
search: added basic example query block.
r1684 query_lang_doc = ''
dan
search: add support for elastic search 6...
r3319 es_version = None
name = None
search: added basic example query block.
r1684
project: added all source files and assets
r1 def __init__(self):
pass
def cleanup(self):
pass
search: goto commit search will now use a safe search option and never...
r1411 def search(self, query, document_type, search_user, repo_name=None,
raise_on_exc=True):
project: added all source files and assets
r1 raise Exception('NotImplemented')
dan
search: add support for elastic search 6...
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.
search: goto commit search will now use a safe search option and never...
r1411
dan
search: add support for elastic search 6...
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 {}
def search_config(config, prefix='search.'):
project: added all source files and assets
r1 _config = {}
for key in config.keys():
if key.startswith(prefix):
_config[key[len(prefix):]] = config[key]
dan
search: add support for elastic search 6...
r3319 return _config
def searcher_from_config(config, prefix='search.'):
_config = search_config(config, prefix)
project: added all source files and assets
r1
if 'location' not in _config:
_config['location'] = default_location
dan
search: add support for elastic search 6...
r3319 if 'es_version' not in _config:
# use old legacy ES version set to 2
_config['es_version'] = '2'
project: added all source files and assets
r1 imported = importlib.import_module(_config.get('module', default_searcher))
dan
search: add support for elastic search 6...
r3319 searcher = imported.Searcher(config=_config)
project: added all source files and assets
r1 return searcher