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.

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]
filter(queryset)[source]

Filter.

Parameters:queryset
Returns:
get_all_query_params()[source]
get_backend_default_fields_params()[source]

Get backend default filter params.

Return type:dict
Returns:
get_field_type(field_name, field_value, base_field_type)[source]

Get field type.

Returns:
has_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

Module contents