Search query

Advanced search query.

Overview

In URLs, query parameters are defined sets of parameters. By using them, you can define specific content or actions based on the data being passed.

A search query is used in Labii to limit the search results, apply filters, and integrate into many widgets.

Query format

A query contains the following parts:

[field]__[expression]=value

# Example:
name__icontains=test

Query expression

Here are list of supported expressions:

  • contains: Returns results that match the provided value, case sensitive.

  • not_contains: Returns results that does not match the provided value, case sensitive.

  • icontains: Returns results that match the provided value, regardless of case.

  • not_icontains: Returns results that does not match the provided value, regardless of case.

  • jcontains: Returns results that match the provided value with a JSON field.

  • not_jcontains: Returns results that does not match the provided value with a JSON field.

  • acontains: Returns results that a comma-separated list of values exists within a JSON array field.

  • asimilarity: Retrieve results that exceed a specified similarity percentage by comparing a JSON field in the model with a comma-separated input string.

    • asimilarity_65: Returns results with over 65% similarity between a JSON field in the model and a comma-separated input string.

    • asimilarity_75: Returns results with over 75% similarity between a JSON field in the model and a comma-separated input string.

    • asimilarity_85: Returns results with over 85% similarity between a JSON field in the model and a comma-separated input string.

    • asimilarity_95: Returns results with over 95% similarity between a JSON field in the model and a comma-separated input string.

  • gt: Returns results that is greater than the provided value.

  • gte: Returns results that is greater than or equal to the provided value.

  • lt: Returns results that is less than the provided value.

  • lte: Returns results that is less than or equal to the provided value.

  • int: Convert the database value into integer

  • asdate: Convert the database value into a date object

  • asstring: Convert the database value into a string

  • ne: Returns results that does not equal to the provided value.

Multiple expressions can be chained together with "__":

# convert the date-start into date and return the records that greater than 2022-02-01
date_start__date__gte=2022-02-01

Query by multiple fields

Use & to connect the queries for multiple fields.

name__icontains=test&is_archived=false

Filter in JSON objects

  • contains a string in value: jsonfield__icontains=test

  • not contain a string in value: jsonfield__not_contains=test

  • contains a key: jsonfield__has_key=test

  • contains an object: jsonfield__jcontains={'name':'test'}

  • not contains an object: jsonfield__not_jcontains={'name':'test'}

  • Filter by a filter set: filter__sid=xxx, wherein a filter set:

    • AND relationship shall be expressed in a JSON object, separate by a comma: {"name__icontains":"test", "is_archived":false}

    • AND relationship expressed in JSON array: {"and": [{"name__icontains":"test"}, {"is_archived":false}]}

    • OR relationship shall be expressed in an array: {"or": [{"name__icontains":"test"}, {"is_archived":false}]}

  • Filter by multiple filter set:

    • AND: filter__sid=xxx,xxx

    • OR: filter__sid__in=xxx,xxx

  • Filter by json query, the query is same to the filter set:

    • jquery={a:1,b:2,c=3}

    • jquery={"or": [{sid:aa,data:bb}, {sid:aa,data:bb}]}

    • jquery={"and": [{sid:aa,data:bb}, {sid:aa,data:bb}]}

Since the database JSON field no longer supports the Array data. We have updated ["or", {sid:aa,data:bb}, {sid:aa,data:bb}] to {"or": [{sid:aa,data:bb}, {sid:aa,data:bb}]}

Examples

  1. All unsigned experiments:

    {"is_archived": false, "is_locked": false}
  2. All unfinished experiments (Experiments in which at least one signer has not signed):

    {"is_archived": false, "signer__signature__isnull": true}
  3. Sign but unfinished experiments (Signed experiments with at least one unsigned witnesses):

    {"is_archived": false, "signer__signature__isnull": true, "is_locked": true}

Last updated