def test_with_both_tag_and_tags(self): """If both 'tag' and 'tags' params are used they should all become tags.""" params = {'tag': 'foo', 'tags': 'bar'} result = query.TagsMatcher()(params) assert list(result.keys()) == ['bool'] assert list(result['bool'].keys()) == ['must'] assert len(result['bool']['must']) == 2 assert { 'match': { 'tags': { 'query': 'foo', 'operator': 'and' } } } in result['bool']['must'] assert { 'match': { 'tags': { 'query': 'bar', 'operator': 'and' } } } in result['bool']['must']
def test_aliases_tag_to_tags(self): """'tag' params should be transformed into 'tags' queries. 'tag' is aliased to 'tags' because users often type tag instead of tags. """ params = multidict.MultiDict() params.add('tag', 'foo') params.add('tag', 'bar') result = query.TagsMatcher()(params) assert list(result.keys()) == ['bool'] assert list(result['bool'].keys()) == ['must'] assert len(result['bool']['must']) == 2 assert { 'match': { 'tags': { 'query': 'foo', 'operator': 'and' } } } in result['bool']['must'] assert { 'match': { 'tags': { 'query': 'bar', 'operator': 'and' } } } in result['bool']['must']
def default_querybuilder(request): builder = query.Builder() builder.append_filter(query.AuthFilter(request)) builder.append_filter(query.UriFilter(request)) builder.append_filter(query.GroupFilter()) builder.append_filter(query.UserFilter()) builder.append_matcher(query.AnyMatcher()) builder.append_matcher(query.TagsMatcher()) for factory in request.registry.get(FILTERS_KEY, []): builder.append_filter(factory(request)) for factory in request.registry.get(MATCHERS_KEY, []): builder.append_matcher(factory(request)) return builder