graphene_elastic.filter_backends.filtering package¶
Submodules¶
graphene_elastic.filter_backends.filtering.common module¶
-
class
graphene_elastic.filter_backends.filtering.common.
FilteringFilterBackend
(connection_field, args=None)[source]¶ Bases:
graphene_elastic.filter_backends.base.BaseBackend
,graphene_elastic.filter_backends.filtering.mixins.FilteringFilterMixin
Filtering filter backend.
-
field_belongs_to
(field_name)[source]¶ Check if given filter field belongs to the backend.
Parameters: field_name – Returns:
-
filter_args_mapping
¶
-
filter_fields
¶ Filtering filter fields.
-
get_backend_query_fields
(items, is_filterable_func, get_type_func)[source]¶ Fail proof override.
Parameters: - items –
- is_filterable_func –
- get_type_func –
Returns:
-
get_field_lookup_param
(field_name)[source]¶ Get field lookup param.
Parameters: field_name – Returns:
-
get_filter_query_params
()[source]¶ Get query params to be filtered on.
We can either specify it like this:
- query_params = {
- ‘category’: {
- ‘value’: ‘Elastic’,
}
}
Or using specific lookup:
- query_params = {
- ‘category’: {
‘term’: ‘Elastic’, ‘range’: {
‘lower’: Decimal(‘3.0’)}
}
}
Note, that value would only work on simple types (string, integer, decimal). For complex types you would have to use complex param anyway. Therefore, it should be forbidden to set default_lookup to a complex field type.
Sample values:
- query_params = {
- ‘category’: {
- ‘value’: ‘Elastic’,
}
}
- filter_fields = {
- ‘category’: {
‘field’: ‘category.raw’, ‘default_lookup’: ‘term’, ‘lookups’: (
‘term’, ‘terms’, ‘range’, ‘exists’, ‘prefix’, ‘wildcard’, ‘contains’, ‘in’, ‘gt’, ‘gte’, ‘lt’, ‘lte’, ‘starts_with’, ‘ends_with’, ‘is_null’, ‘exclude’)
}
}
field_name = ‘category’
-
has_query_fields
= True¶
-
prefix
= 'filter'¶
-
prepare_filter_fields
()[source]¶ Prepare filter fields.
Possible structures:
- filter_fields = {
- ‘title’: {
‘field’: ‘title.raw’, ‘lookups’: [
LOOKUP_FILTER_TERM, LOOKUP_FILTER_TERMS, LOOKUP_FILTER_PREFIX, LOOKUP_FILTER_WILDCARD, LOOKUP_QUERY_IN, LOOKUP_QUERY_EXCLUDE,], ‘default_lookup’: LOOKUP_FILTER_TERM,
}, ‘category’: ‘category.raw’,
}
We shall finally have:
- filter_fields = {
- ‘title’: {
‘field’: ‘title.raw’, ‘lookups’: [
LOOKUP_FILTER_TERM, LOOKUP_FILTER_TERMS, LOOKUP_FILTER_PREFIX, LOOKUP_FILTER_WILDCARD, LOOKUP_QUERY_IN, LOOKUP_QUERY_EXCLUDE,], ‘default_lookup’: LOOKUP_FILTER_TERM,
}, ‘category’: {
‘field’: ‘category.raw’, ‘lookups’: [
LOOKUP_FILTER_TERM, LOOKUP_FILTER_TERMS, LOOKUP_FILTER_PREFIX, LOOKUP_FILTER_WILDCARD, LOOKUP_QUERY_IN, LOOKUP_QUERY_EXCLUDE, … # All other lookups], ‘default_lookup’: LOOKUP_FILTER_TERM,
}
}
-