graphene_elastic.filter_backends.search package¶
Submodules¶
graphene_elastic.filter_backends.search.common module¶
-
class
graphene_elastic.filter_backends.search.common.
SearchFilterBackend
(connection_field, args=None)[source]¶ Bases:
graphene_elastic.filter_backends.base.BaseBackend
Search filter backend.
-
construct_search
()[source]¶ Construct search.
We have to deal with two types of structures:
Type 1:
>>> search_fields = ( >>> 'title', >>> 'description', >>> 'summary', >>> )
Type 2:
>>> search_fields = { >>> 'title': {'field': 'title', 'boost': 2}, >>> 'description': None, >>> 'summary': None, >>> }
In GraphQL shall be:
- query {
- allPostDocuments(search:{
- query:”Another”, title:{value:”Another”} summary:{value:”Another”}
}) { pageInfo {
startCursor endCursor hasNextPage hasPreviousPage} edges {
cursor node {
category title content numViews}
}
}
}
Or simply:
- query {
- allPostDocuments(search:{query:”education technology”}) {
- pageInfo {
- startCursor endCursor hasNextPage hasPreviousPage
} edges {
cursor node {
category title content numViews}
}
}
}
Returns: Updated queryset. Return type: elasticsearch_dsl.search.Search
-
field_belongs_to
(field_name)[source]¶ Check if given filter field belongs to the backend.
Parameters: field_name – Returns:
-
get_backend_default_query_fields_params
()[source]¶ Get backend default filter params.
Return type: dict Returns:
-
has_query_fields
= True¶
-
prefix
= 'search'¶
-
prepare_search_fields
()[source]¶ Prepare search fields.
Possible structures:
- search_fields = {
- ‘title’: {‘boost’: 4, ‘field’: ‘title.raw’}, ‘content’: {‘boost’: 2}, ‘category’: None,
}
We shall finally have:
- search_fields = {
- ‘title’: {
- ‘field’: ‘title.raw’, ‘boost’: 4
}, ‘content’: {
‘field’: ‘content’, ‘boost’: 2}, ‘category’: {
‘field’: ‘category’}
}
Sample query would be:
- {
- allPostDocuments(search:{query:”Another”}) {
- pageInfo {
- startCursor endCursor hasNextPage hasPreviousPage
} edges {
cursor node {
category title content numViews}
}
}
}
Returns: Filtering options. Return type: dict
-
search_args_mapping
¶
-
search_fields
¶ Search filter fields.
-