Mercurial > repos > shellac > sam_consensus_v3
diff env/lib/python3.9/site-packages/galaxy/util/search.py @ 0:4f3585e2f14b draft default tip
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
author | shellac |
---|---|
date | Mon, 22 Mar 2021 18:12:50 +0000 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/env/lib/python3.9/site-packages/galaxy/util/search.py Mon Mar 22 18:12:50 2021 +0000 @@ -0,0 +1,33 @@ +import re + + +def parse_filters(search_term, filters): + """Support github-like filters for narrowing the results. + + Order of chunks does not matter, only recognized filter names are allowed. + + :param search_term: the original search str from user input + + :returns allow_query: whoosh Query object used for filtering + results of searching in index + :returns search_term_without_filters: str that represents user's + search phrase without the filters + """ + allow_terms = [] + search_term_without_filters = None + search_space = search_term.replace('"', "'") + filter_keys = "|".join(list(filters.keys())) + pattern = fr"({filter_keys}):(\w+|\'.*?\')" + reserved = re.compile(pattern) + while True: + match = reserved.search(search_space) + if match is None: + search_term_without_filters = ' '.join(search_space.split()) + break + first_group = match.groups()[0] + if first_group in filters: + filter_as = filters[first_group] + allow_terms.append((filter_as, match.groups()[1].strip().replace("'", ""))) + search_space = search_space[0:match.start()] + search_space[match.end():] + allow_query = allow_terms if len(allow_terms) > 0 else None + return allow_query, search_term_without_filters