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

Filtering filter backend.

classmethod apply_filter_prefix(queryset, options, value)[source]

Apply prefix filter.

Syntax:

TODO

Example:

query {
allPostDocuments(filter:{category:{prefix:”Pyth”}}) {
edges {
node {
category title content numViews comments

}

}

}

}

Parameters:
  • queryset (elasticsearch_dsl.search.Search) – Original queryset.
  • options (dict) – Filter options.
  • value (str) – value to filter on.
Returns:

Modified queryset.

Return type:

elasticsearch_dsl.search.Search

classmethod apply_filter_range(queryset, options, value)[source]

Apply range filter.

Syntax:

TODO

Example:

{
allPostDocuments(filter:{numViews:{range:{
lower:”100”, upper:”200”

}}}) {

edges {
node {
category title content numViews

}

}

}

}

Parameters:
  • queryset (elasticsearch_dsl.search.Search) – Original queryset.
  • options (dict) – Filter options.
  • value (str) – value to filter on.
Returns:

Modified queryset.

Return type:

elasticsearch_dsl.search.Search

classmethod apply_filter_term(queryset, options, value)[source]

Apply term filter.

Syntax:

TODO

Example:

query {
allPostDocuments(filter:{category:{term:”Python”}}) {
edges {
node {
category title content numViews comments

}

}

}

}

Parameters:
  • queryset (elasticsearch_dsl.search.Search) – Original queryset.
  • options (dict) – Filter options.
  • value (str) – value to filter on.
Returns:

Modified queryset.

Return type:

elasticsearch_dsl.search.Search

classmethod apply_filter_terms(queryset, options, value)[source]

Apply terms filter.

Syntax:

TODO

Note, that number of values is not limited.

Example:

query {
allPostDocuments(filter:{category:{
terms:[“Python”, “Django”]

}}) {

edges {
node {
category title content numViews comments

}

}

}

}

Parameters:
  • queryset (elasticsearch_dsl.search.Search) – Original queryset.
  • options (dict) – Filter options.
  • value (mixed: either str or iterable (list, tuple)) – value to filter on.
Returns:

Modified queryset.

Return type:

elasticsearch_dsl.search.Search

classmethod apply_query_contains(queryset, options, value)[source]

Apply contains filter.

Syntax:

TODO

Example:

query {
allPostDocuments(filter:{category:{contains:”tho”}}) {
edges {
node {
category title content numViews

}

}

}

}

Parameters:
  • queryset (elasticsearch_dsl.search.Search) – Original queryset.
  • options (dict) – Filter options.
  • value (str) – value to filter on.
Returns:

Modified queryset.

Return type:

elasticsearch_dsl.search.Search

classmethod apply_query_endswith(queryset, options, value)[source]

Apply endswith filter.

Syntax:

TODO

Example:

query {
allPostDocuments(filter:{category:{endsWith:”thon”}}) {
edges {
node {
category title content numViews

}

}

}

}

Parameters:
  • queryset (elasticsearch_dsl.search.Search) – Original queryset.
  • options (dict) – Filter options.
  • value (str) – value to filter on.
Returns:

Modified queryset.

Return type:

elasticsearch_dsl.search.Search

classmethod apply_query_exclude(queryset, options, value)[source]

Apply exclude functional query.

Syntax:

TODO

Note, that number of values is not limited.

Example:

query {
allPostDocuments(filter:{category:{exclude:”Python”}}) {
edges {
node {
category title content numViews

}

}

}

}

Or exclude multiple terms at once:

query {
allPostDocuments(filter:{category:{exclude:[“Ruby”, “Java”]}}) {
edges {
node {
category title content numViews

}

}

}

}

Parameters:
  • queryset (elasticsearch_dsl.search.Search) – Original queryset.
  • options (dict) – Filter options.
  • value (str) – value to filter on.
Returns:

Modified queryset.

Return type:

elasticsearch_dsl.search.Search

classmethod apply_query_exists(queryset, options, value)[source]

Apply exists filter.

Syntax:

TODO

Example:

{
allPostDocuments(filter:{category:{exists:true}}) {
edges {
node {
category title content numViews

}

}

}

}

Parameters:
  • queryset (elasticsearch_dsl.search.Search) – Original queryset.
  • options (dict) – Filter options.
  • value (str) – value to filter on.
Returns:

Modified queryset.

Return type:

elasticsearch_dsl.search.Search

classmethod apply_query_gt(queryset, options, value)[source]

Apply gt functional query.

Syntax:

TODO

Example:

query {
allPostDocuments(filter:{numViews:{gt:”100”}}) {
edges {
node {
category title content numViews

}

}

}

}

Parameters:
  • queryset (elasticsearch_dsl.search.Search) – Original queryset.
  • options (dict) – Filter options.
  • value (str) – value to filter on.
Returns:

Modified queryset.

Return type:

elasticsearch_dsl.search.Search

classmethod apply_query_gte(queryset, options, value)[source]

Apply gte functional query.

Syntax:

TODO

Example:

query {
allPostDocuments(filter:{numViews:{gte:”100”}}) {
edges {
node {
category title content numViews

}

}

}

}

Parameters:
  • queryset (elasticsearch_dsl.search.Search) – Original queryset.
  • options (dict) – Filter options.
  • value (str) – value to filter on.
Returns:

Modified queryset.

Return type:

elasticsearch_dsl.search.Search

classmethod apply_query_in(queryset, options, value)[source]

Apply in functional query.

Syntax:

TODO

Note, that number of values is not limited.

Example:

query {
allPostDocuments(filter:{tags:{in:[“photography”, “models”]}}) {
edges {
node {
category title content numViews tags

}

}

}

}

Parameters:
  • queryset (elasticsearch_dsl.search.Search) – Original queryset.
  • options (dict) – Filter options.
  • value (str) – value to filter on.
Returns:

Modified queryset.

Return type:

elasticsearch_dsl.search.Search

classmethod apply_query_isnull(queryset, options, value)[source]

Apply isnull functional query.

Syntax:

TODO

Example:

query {
allPostDocuments(filter:{category:{isNull:true}}) {
edges {
node {
category title content numViews comments

}

}

}

}

Parameters:
  • queryset (elasticsearch_dsl.search.Search) – Original queryset.
  • options (dict) – Filter options.
  • value (str) – value to filter on.
Returns:

Modified queryset.

Return type:

elasticsearch_dsl.search.Search

classmethod apply_query_lt(queryset, options, value)[source]

Apply lt functional query.

Syntax:

TODO

Example:

query {
allPostDocuments(filter:{numViews:{lt:”200”}}) {
edges {
node {
category title content numViews

}

}

}

}

Parameters:
  • queryset (elasticsearch_dsl.search.Search) – Original queryset.
  • options (dict) – Filter options.
  • value (str) – value to filter on.
Returns:

Modified queryset.

Return type:

elasticsearch_dsl.search.Search

classmethod apply_query_lte(queryset, options, value)[source]

Apply lte functional query.

Syntax:

TODO

Example:

query {
allPostDocuments(filter:{numViews:{lte:”200”}}) {
edges {
node {
category title content numViews

}

}

}

}

Parameters:
  • queryset (elasticsearch_dsl.search.Search) – Original queryset.
  • options (dict) – Filter options.
  • value (str) – value to filter on.
Returns:

Modified queryset.

Return type:

elasticsearch_dsl.search.Search

classmethod apply_query_wildcard(queryset, options, value)[source]

Apply wildcard filter.

Syntax:

TODO

Example:

query {
allPostDocuments(filter:{category:{wildcard:”ytho”}}) {
edges {
node {
category title content numViews comments

}

}

}

}

Parameters:
  • queryset (elasticsearch_dsl.search.Search) – Original queryset.
  • options (dict) – Filter options.
  • value (str) – value to filter on.
Returns:

Modified queryset.

Return type:

elasticsearch_dsl.search.Search

field_belongs_to(field_name)[source]
filter(queryset)[source]

Filter.

get_field_lookup_param(field_name)[source]

Get field lookup param.

Parameters:field_name
Returns:
get_field_options(field_name)[source]

Get field option params.

Parameters:field_name
Returns:
get_field_type(field_name, field_value, base_field_type)[source]

Get field type.

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’

classmethod get_gte_lte_params(value, lookup, options)[source]

Get params for gte, gt, lte and lt query.

Syntax:

TODO

Example:

{
allPostDocuments(filter:{numViews:{gt:”100”, lt:”200”}}) {
edges {
node {
category title content numViews

}

}

}

}

Parameters:
  • value (str) –
  • lookup (str) –
  • options (dict) –
Returns:

Params to be used in range query.

Return type:

dict

classmethod get_range_params(value, options)[source]

Get params for range query.

Syntax:

TODO

Example:

{
allPostDocuments(filter:{numViews:{range:{
lower:”100”, upper:”200”, boost:”2.0”

}}}) {

edges {
node {
category title content numViews

}

}

}

}

Parameters:
  • value (str) –
  • options (dict) –
Returns:

Params to be used in range query.

Return type:

dict

has_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,

}

}

prepare_query_params()[source]

Prepare query params.

Returns:

Module contents