comparison 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
comparison
equal deleted inserted replaced
-1:000000000000 0:4f3585e2f14b
1 import re
2
3
4 def parse_filters(search_term, filters):
5 """Support github-like filters for narrowing the results.
6
7 Order of chunks does not matter, only recognized filter names are allowed.
8
9 :param search_term: the original search str from user input
10
11 :returns allow_query: whoosh Query object used for filtering
12 results of searching in index
13 :returns search_term_without_filters: str that represents user's
14 search phrase without the filters
15 """
16 allow_terms = []
17 search_term_without_filters = None
18 search_space = search_term.replace('"', "'")
19 filter_keys = "|".join(list(filters.keys()))
20 pattern = fr"({filter_keys}):(\w+|\'.*?\')"
21 reserved = re.compile(pattern)
22 while True:
23 match = reserved.search(search_space)
24 if match is None:
25 search_term_without_filters = ' '.join(search_space.split())
26 break
27 first_group = match.groups()[0]
28 if first_group in filters:
29 filter_as = filters[first_group]
30 allow_terms.append((filter_as, match.groups()[1].strip().replace("'", "")))
31 search_space = search_space[0:match.start()] + search_space[match.end():]
32 allow_query = allow_terms if len(allow_terms) > 0 else None
33 return allow_query, search_term_without_filters