##// END OF EJS Templates
hovercards: handle unknown commits on repo by returning 404 instead of 500 error.
hovercards: handle unknown commits on repo by returning 404 instead of 500 error.

File last commit:

r3968:2ec277c2 default
r4110:15b821fa default
Show More
__init__.py
152 lines | 4.5 KiB | text/x-python | PythonLexer
project: added all source files and assets
r1 # -*- coding: utf-8 -*-
docs: updated copyrights to 2019
r3363 # Copyright (C) 2012-2019 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: allow result sorting for elasticsearch6
r3963 DIRECTION_ASC = 'asc'
DIRECTION_DESC = 'desc'
search: added basic example query block.
r1684
project: added all source files and assets
r1 def __init__(self):
pass
def cleanup(self):
pass
dan
search: add option to search within a repository group.
r3441 def search(self, query, document_type, search_user,
repo_name=None, repo_group_name=None,
search: goto commit search will now use a safe search option and never...
r1411 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 {}
dan
search: new UI for search, and repo group context search...
r3442 @staticmethod
def extract_search_tags(query):
return []
dan
search: allow quick search for path globally
r3542 @staticmethod
def escape_specials(val):
"""
Handle and escape reserved chars for search
"""
return val
dan
search: added per-backend sorting fields....
r3968 def sort_def(self, search_type, direction, sort_field):
"""
Defines sorting for search. This function should decide if for given
search_type, sorting can be done with sort_field.
It also should translate common sort fields into backend specific. e.g elasticsearch
"""
raise NotImplementedError()
search: allow result sorting for elasticsearch6
r3963 @staticmethod
def get_sort(search_type, search_val):
"""
Method used to parse the GET search sort value to a field and direction.
e.g asc:lines == asc, lines
There's also a legacy support for newfirst/oldfirst which defines commit
sorting only
"""
direction = BaseSearcher.DIRECTION_ASC
sort_field = None
if not search_val:
return direction, sort_field
if search_val.startswith('asc:'):
sort_field = search_val[4:]
direction = BaseSearcher.DIRECTION_ASC
elif search_val.startswith('desc:'):
sort_field = search_val[5:]
direction = BaseSearcher.DIRECTION_DESC
elif search_val == 'newfirst' and search_type == 'commit':
sort_field = 'date'
direction = BaseSearcher.DIRECTION_DESC
elif search_val == 'oldfirst' and search_type == 'commit':
sort_field = 'date'
direction = BaseSearcher.DIRECTION_ASC
return direction, sort_field
dan
search: add support for elastic search 6...
r3319
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