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:
BaseBackend
Search filter backend.
- construct_nested_search()[source]¶
Construct nested search.
Type 1:
>>> search_nested_fields = { >>> "comments": { >>> "path": "comments", >>> "fields": [ >>> "tag", >>> "content" >>> ] >>> }
Type 2:
>>> search_nested_fields = { >>> "comments": { >>> "path": "comments", >>> "fields": [ >>> { >>> "tag": { >>> "field": "tag.raw", >>> "boost": 4 >>> } >>> }, >>> { >>> "content": { >>> "field": "content", >>> "boost": 2 >>> } >>> } >>> ] >>> }
In GraphQL shall be:
- query {
- allPostDocuments(search:{
- comments: {
- tag: {
value: “Python”, boost: 2
}
}
}) { pageInfo {
startCursor endCursor hasNextPage hasPreviousPage
} edges {
cursor node {
category title content numViews comments{
tag
}
}
}
}
}
Or simply:
- query {
- allPostDocuments(search:{query:”Python”}) {
- pageInfo {
startCursor endCursor hasNextPage hasPreviousPage
} edges {
cursor node {
category title content numViews comments{
tag
}
}
}
}
}
- Returns:
Updated queryset.
- Return type:
elasticsearch_dsl.search.Search
- 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:
- get_field_type(field_name, field_value, base_field_type)[source]¶
Get field type.
- Returns:
TODO: required
- get_search_nested_fields_tree(start=None, value=None)[source]¶
We got a prepared nested fields ,
- {
- ‘country’: {
‘path’: ‘country’, ‘fields’: [
- {
‘name’: {‘boost’: 2}
}
]
}, ‘city’: {
‘path’: ‘country.city’, ‘fields’: [
- {
‘name’: {‘boost’: 2}
}
]
}
}
Then we should turn it to
- {
- ‘country’: {
‘name’: {}, # {} or None represents no more leaves. ‘city’: {
‘name’: {}
}
}
}
- has_query_fields = True¶
- property nested_search_args_mapping¶
- prefix = 'search'¶
- prepare_search_fields()[source]¶
Prepare search fields.
Possible structures:
- search_fields = {
‘title’: {‘boost’: 4, ‘field’: ‘title.raw’}, ‘content’: {‘boost’: 2}, ‘category’: None, ‘comments’: 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
- prepare_search_nested_fields()[source]¶
Prepare search fields.
Possible structures:
- Type1
- search_nested_fields = {
- ‘comments’: {
‘path’; ‘comments’, ‘fields’: [
{‘author’: {‘boost’: 4}}, {‘tag’: {‘boost’: 2}},
]
}
}
- Type2
- search_nested_fields = {
- ‘comments: {
‘path’; ‘comments’, ‘fields’: [‘author’, ‘tag’]
}
}
We shall finally have:
- search_nested_fields = {
- ‘comments’: {
‘path’: ‘comments’, ‘fields’: {
{‘author’: {‘boost’: 4}}, {‘tag’: {‘boost’: 2}}
}
}
}
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
- property search_args_mapping¶
- property search_fields¶
Search filter fields.
- property search_nested_fields¶
Search nested filter fields.
graphene_elastic.filter_backends.search.query_string module¶
- class graphene_elastic.filter_backends.search.query_string.QueryStringBackend(connection_field, args=None)[source]¶
Bases:
BaseBackend
- get_backend_query_fields(items, is_filterable_func, get_type_func)[source]¶
Construct backend query fields.
- Parameters:
items –
is_filterable_func –
get_type_func –
- Returns:
- has_query_fields = True¶
- prefix = 'query_string'¶
- property query_string_options¶
Query string options.
Possible options:
- query_string_options = {
‘fields’: [‘title’, ‘category’, ‘tag’], ‘default_operator’: “and”, ‘lenient’: true, ‘minimum_should_match’: 3
}
For list of all options: https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-simple-query-string-query.html
graphene_elastic.filter_backends.search.simple_query_string module¶
- class graphene_elastic.filter_backends.search.simple_query_string.SimpleQueryStringBackend(connection_field, args=None)[source]¶
Bases:
BaseBackend
- get_backend_query_fields(items, is_filterable_func, get_type_func)[source]¶
Construct backend query fields.
- Parameters:
items –
is_filterable_func –
get_type_func –
- Returns:
- has_query_fields = True¶
- prefix = 'simple_query_string'¶
- property simple_query_string_options¶
Simple query string options.
Possible options:
- simple_query_string_options = {
‘fields’: [‘title’, ‘category’, ‘tag’], ‘default_operator’: “and”, ‘lenient’: true, ‘minimum_should_match’: 3
}
For list of all options: https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-simple-query-string-query.html