Currently, parse_query_string separates out filter queries (in the form of filter:value) from the rest of the query, using a regular expression. This is hard-coded in the file as filters_regexp. However, I would like to extend this to allow hyphens in the filter values without quotes (e.g. "foo:value-with-hyphens"). This is a trivial change to the regex, but because the value is hard-coded, changing this would require duplicating separate_filters_from_query just to change the expression.
Proposed solution
Change the signature of separate_filters_from_query and parse_query_string to have an optional filter_regex parameter which defaults to the existing expression:
DEFAULT_FILTER_REGEXP = re.compile(r'\b(\w+):(\w+|"[^"]+"|\'[^\']+\')')
def separate_filters_from_query(query_string, filters_regexp=DEFAULT_FILTER_REGEXP):
... # The method body is unchanged.
def parse_query_string(query_string, operator=None, zero_terms=MATCH_NONE, filters_regexp=DEFAULT_FILTER_REGEXP):
filters, query_string = separate_filters_from_query(query_string, filters_regexp=filters_regexp)
# Remaining method body unchanged.
This would allow users to easily customize the regular expression for their own needs. Examples would include the one I mentioned above, or perhaps replacing the colon with an equals sign (filter=foo).
If this is something people think could be reasonable, I could try my hand at making a merge request. Wanted to clear with the maintainers first though.
Currently,
parse_query_stringseparates out filter queries (in the form offilter:value) from the rest of the query, using a regular expression. This is hard-coded in the file asfilters_regexp. However, I would like to extend this to allow hyphens in the filter values without quotes (e.g. "foo:value-with-hyphens"). This is a trivial change to the regex, but because the value is hard-coded, changing this would require duplicatingseparate_filters_from_queryjust to change the expression.Proposed solution
Change the signature of
separate_filters_from_queryandparse_query_stringto have an optionalfilter_regexparameter which defaults to the existing expression:This would allow users to easily customize the regular expression for their own needs. Examples would include the one I mentioned above, or perhaps replacing the colon with an equals sign (
filter=foo).If this is something people think could be reasonable, I could try my hand at making a merge request. Wanted to clear with the maintainers first though.