graphene_elastic.filter_backends.highlight package

Submodules

graphene_elastic.filter_backends.highlight.common module

class graphene_elastic.filter_backends.highlight.common.HighlightFilterBackend(connection_field, args=None)[source]

Bases: BaseBackend

Highlight filter backend.

field_belongs_to(field_name)[source]

Check if given filter field belongs to the backend.

Parameters:

field_name

Returns:

filter(queryset)[source]

Filter.

Parameters:

queryset

Returns:

get_backend_document_fields()[source]

Get additional document fields for the backend.

For instance, the Highlight backend add additional field named highlight to the list of fields.

Sample query:

query {
allPostDocuments(search:{title:{value:”alice”}}) {
edges {
node {

id title highlight

}

}

}

}

Sample response:

{
“data”: {
“allPostDocuments”: {
“edges”: [
{
“node”: {

“id”: “UG9zdDp5a1ppVlcwQklwZ2dXbVlJQV91Rw==”, “title”: “thus Alice style”, “highlight”: {

“title”: [

“thus <b>Alice</b> style”

]

}

}

]

}

}

}

That highlight part on both sample query and sample response isn’t initially available on the connection level, but added with help of the filter backend. :return:

get_backend_query_fields(items, is_filterable_func, get_type_func)[source]

Construct backend filtering fields.

Parameters:
  • items

  • is_filterable_func

  • get_type_func

Returns:

get_highlight_query_params()[source]

Get highlight query params.

Returns:

List of search query params.

Return type:

list

has_query_fields = True
property highlight_fields

Highlight filter fields.

prefix = 'highlight'
prepare_highlight_fields()[source]

Prepare highlight fields.

Possible structures:

highlight_fields = {
‘title’: {

‘enabled’: True, ‘options’: {

‘pre_tags’: [“<b>”], ‘post_tags’: [“</b>”],

}

}, ‘summary’: {

‘options’: {

‘fragment_size’: 50, ‘number_of_fragments’: 3

}

}, ‘description’: {},

}

Sample query would be:

query {
allPostDocuments(

search:{content:{value:”since”}, title:{value:”decide”}}, highlight:[category, content]

) { edges {

node {

title content highlight

} cursor

}

}

}

Returns:

Filtering options.

Return type:

dict

Module contents