Athento's advanced search allows you to perform search filters dynamically. These searches are applied directly on the Athento Search Engine configured in the instance and will offer the results according to the filters applied.
The following is a general description of how to use the most important packages.
Here we find each of the different search engines added to Athento, all of them have an identical structure and are composed of two inseparable classes:
- Search Engine: defines the functionality of the search engine.
- Filters: defines the different filters that can be invoked from the engine.
Search
Athento allows complex searches to be performed on the files found on the platform. To perform these searches, it is necessary to define a structure of groups and rules, which will define the filter that will be applied to a set of files.
Searches can be performed on deleted or non-deleted documents using, for the search on deleted documents, the clause ecm:isTrashed with value true or 1. In the instantiation of the search engine, it will be necessary to indicate the attribute (optional with default value False) removed in charge of internally discriminating.
Execution
from search.searchengine.elasticsearch.advanced_search import ElasticsearchSearchEngine
user = User.objects.get(username="<username>")
engine = ElasticsearchSearchEngine(removed=False)
filters = { ... }
engine.advanced_search(user, filters)
Filters
The structure of the filters is the same as the one applied in the search using the Django ORM. This structure is transformed into the language that is used by Elasticsearch.
The structure of a filter is composed of groups of rules unified by a conjunction and rules.
{
"AND": [ # Grupo inicial A (Conjunto de reglas unidas por la conjuncion "AND")
{ # Regla A1 en grupo A
"type": "serie",
"schema": {
"value": ["123-123-213", "321-321-321"]
}
},
{ # Regla A2 en grupo A
"type": "doctype",
"schema": {
"value": ["123-123-123", "321-321-321"]
}
},
{ # Regla A3 en grupo A (otro grupo, B)
"AND": [ # Grupo B (Conjunto de reglas unidas por la conjunción "AND")
{ # Regla B1
"type": "metadata",
"schema": {
"uuid": "123-123-123",
"value": ["myValueA", "myValueB"],
"lookup_type": "contains",
"negate": False
}
},
{ # Regla B2
"type": "metadata",
"schema": {
"uuid": "321-321-321",
"value": ["myValue2A", "myValue2B"],
"lookup_type": "contains",
"negate": False
}
},
{ # Regla B3 en grupo B
"OR": [ # Grupo C (Conjunto de reglas unidas por la conjunción "OR")
{ # Regla C1
"type": "metadata",
"schema": {
"uuid": "111-111-111",
"value": ["myValue111A", "myValue111B"],
"lookup_type": "contains",
"negate": False
}
},
{ # Regla C2
"type": "metadata",
"schema": {
"uuid": "222-222-222",
"value": ["myValue222A", "myValue222B"],
"lookup_type": "contains",
"negate": False
}
}
]
}
]
}
]
}
Groups
Groups are a set of rules joined by a conjunction. Conjunctions can be AND or OR.
In the filter example above, we can find three groups (A, B and C).
Group A:
This is the initial group containing all the rules. Whenever more than one rule exists, a group will be applied.
Group B:
Group B is a set of AND rules, which also contains a rule that is Group C.
{
"AND": [ # Grupo B (Conjunto de reglas unidas por la conjunción "AND")
{ # Regla B1
"type": "metadata",
"schema": {
"uuid": "123-123-123",
"value": ["myValueA", "myValueB"],
"lookup_type": "contains",
"negate": False
}
},
{ # Regla B2
"type": "metadata",
"schema": {
"uuid": "321-321-321",
"value": ["myValue2A", "myValue2B"],
"lookup_type": "contains",
"negate": False
}
},
{ # Regla B3 en grupo B
"OR": [ # Grupo C (Conjunto de reglas unidas por la conjunción "OR")
{ # Regla C1
"type": "metadata",
"schema": {
"uuid": "111-111-111",
"value": ["myValue111A", "myValue111B"],
"lookup_type": "contains",
"negate": False
}
},
{ # Regla C2
"type": "metadata",
"schema": {
"uuid": "222-222-222",
"value": ["myValue222A", "myValue222B"],
"lookup_type": "contains",
"negate": False
}
}
]
}
]
}
Group C:
Group C is a set of OR rules:
{
"OR": [ # Grupo C (Conjunto de reglas unidas por la conjunción "OR")
{ # Regla C1
"type": "metadato",
"schema": {
"uuid": "111-111-111",
"value": ["myValue111A", "myValue111B"],
"lookup_type": "contains",
"negate": False
}
},
{ # Regla C2
"type": "metadato",
"schema": {
"uuid": "222-222-222",
"value": ["myValue222A", "myValue222B"],
"lookup_type": "contains",
"negate": False
}
}
]
}
Rules
A rule is a key/value dictionary, which will be used to define the filter. There are many types of rules with different configurations:
ORM filters
Filter by series
The filter by series allows filtering by one series or multiple series.
{
"type": "serie",
"schema": {
"value": ["123-123-213", "321-321-321"]
}
}
Where:
Key | Value |
type | serie |
schema[value] | List of UUIDs, either for single or multiple UUIDs. In the case of multiple, an OR shall be applied. |
Examples:
{
"type": "serie",
"schema": {
"value": ["87c217f9-03b4-499b-979f-e56f0b228b7c"]
}
}
{
"type": "serie",
"schema": {
"value": ["87c217f9-03b4-499b-979f-e56f0b228b7c", "656ccfc3-cd14-422b-9a61-ac051e740824"]
}
}
Filter by document type
The filter by document type allows you to filter by one or multiple document types.
{
"type": "doctype",
"schema": {
"value": ["123-123-123", "321-321-321"]
}
}
Where:
Key | Value |
type | doctype |
schema[value] | List of UUIDs, either for single or multiple UUIDs. In the case of multiple, an OR shall be applied. |
Examples:
{"type": "doctype", "schema": {"value": ["8a066e45-da4f-45fc-9bf0-9686f616ea5f"]}}
{
"type": "doctype",
"schema": {
"value": ["8a066e45-da4f-45fc-9bf0-9686f616ea5f", "9686f616ea5f-da4f-45fc-9bf0-9686f616ea5f-8a066e45"]
}
}
Filter by UUID
The filter by UUID, allows you to filter directly by the UUID of a document or multiple documents.
{
"type": "uuid",
"schema": {
"value": ["f9f343d2-d419-4819-906f-03d7acdc3695"]
}
}
Where:
Key | Value |
type | uuid |
schema[value] | List of UUIDs, either for single or multiple UUIDs. In the case of multiple, an OR shall be applied. |
Examples:
{
"type": "uuid",
"schema": {
"value": ["f9f343d2-d419-4819-906f-03d7acdc3695"]
}
}
{
"type": "uuid",
"schema": {
"value": ["f9f343d2-d419-4819-906f-03d7acdc3695", "9467552f-affb-473c-99d9-348ee0a6cecb"]
}
}
Filter by author
Filter by Author, allows you to filter directly by the `uuid` of a user or multiple users.
{
"type": "author",
"schema": {
"value": ["user1-uuid", "user2-uuid"]
}
}
Where:
Key | Value |
type | author |
schema[value] | List of UUIDs, either for single or multiple UUIDs. In the case of multiple, an OR shall be applied. |
Examples:
{
"type": "author",
"schema": {
"value": ["123-321-123"]
}
}
{
"type": "author",
"schema": {
"value": ["123-321-123, 345-543-345"]
}
}
Filter by document status
The filter by document status allows you to filter directly by one or multiple document statuses.
{
"type": "state",
"schema": {
"value": ["pending"]
}
}
Existing additional filters:
- File name
- Document life cycle (type: lifecycle_state)
- Creation date (type: creation_date)
- Modification date (type: modification_date)
- Global text
- Number of pages
- Metadata
Use of dates in filters
The filter by creation date allows you to filter using an operator, an expression or a value (date).
Operator usage
{
"type": "creation_date",
"schema": {
"value": "22-4-2020", "condition": "<"
}
}
Where:
Key | Value |
type | creation_date |
schema[value] | Date to filter by |
schema[condition] | Operator to be applied to perform filtering (`'<', '<=', '==', 'LIKE', '>=', '>'`) |
Use of keyword in condition
Example:
{
"type": "creation_date",
"schema": {
"condition": "last_day",
"value": 2
}
}
Where:
Key | Value |
type | creation_date |
schema[value] | Remaining value as delta to be applied in cases of `last_*` (`'last_month', 'last_year', 'last_day'`) |
schema[condition] | Expression by which to filter ( `'current_month', 'current_year', 'current_day', 'last_month', 'last_year', 'last_day'` ) |
Range
{
"type": "creation_date",
"schema":{
"condition": "range",
"start_date": "21-04-2020",
"end_date": "23-04-2020"
}
}
Where:
Key | Value |
type | creation_date |
schema[start_date] | Start date in range |
schema[end_date] | End date in range |
schema[condition] | range |
Filter by number of pages
The filter by number of pages allows you to filter directly by number or by a range.
{
"type": "num_pages",
"schema": {
"condition": ">",
"value": 10
}
}
Filter by filename
Filter by filename, allows filtering by filename content, exact, insensitive, etc.
{
"type": "filename",
"schema": {
"value": "Mi fichero",
"lookup_type": "contains"
}
}
Where:
Key | Value |
type | filename |
schema[value] | Value for which to search |
schema[lookup_type] | Form in which to search the chain (`'exact', 'iexact', 'contains', 'icontains', 'startswith', 'istartswith', 'endswith', 'iendswith'`) |
Filter globally
The global filter allows you to perform a global search, which is a search on filename or metadata value (text).
{
"type": "text",
"schema": {
"value": "Campo1"
}
}
Filtering by metadata
Filtering by metadata allows us to filter by the value contained in a metadata. Metadata can be of different types. Therefore there are multiple ways of filtering.
The metadata has or does not have a value
Allows us to filter by metadata with value or without value.
{
"type": "metadata",
"schema": {
"uuid": "123-123-123",
"value": ""
}
}
Where:
Key | Value |
type | metadata |
schema[value] | "" (string vacio) to filter by metadata with no value |
schema[uuid] | UUID of the metadata type defining the metadata |
Metadata of type text
Filter by the value of a text type metadata.
{
"type": "metadata",
"schema": {
"uuid": "123-123-123",
"value": ["myValueA", "myValueB"],
"lookup_type": "contains"
}
}
Where:
Key | Value |
type | metadata |
schema[value] | "" (empty string) to filter by metadata with no value |
schema[uuid] | UUID of the metadata type defining the metadata |
schema[lookup_type] | Form in which to search the chain (`'exact', 'iexact', 'contains', 'icontains', 'startswith', 'istartswith', 'endswith', 'iendswith'`) |
Example:
{
"type": "metadata",
"schema": {
"uuid": "df8a0cf4-3a47-4649-a2d4-aaaded3af6e8",
"value": ["Campo11"],
"lookup_type": "exact"
}
}
Metadata of type date
The date type metadata filter allows you to filter using an operator, an expression or a value (date).
Example:
{
"type": "metadata",
"schema": {
"uuid": "123-123-123",
"condition": ">=",
"value": "23-04-2020"
}
}
{
"type": "metadata",
"schema": {
"uuid": "123-123-123",
"condition": "last_day",
"value": 1
}
}
{
"type": "metadata",
"schema": {
"uuid": "123-123-123",
"condition": "range",
"start_date": "23-04-2020",
"end_date": "25-04-2020"
}
}
File type metadata
Allows filtering of file type metadata, by the value of a file UUID.
{
"type": "metadata",
"schema": {
"uuid": "123-123-123",
"value": ["111-222-333"]
}
}
Metadata of type choice or multichoice
This filter allows you to filter by the value of a choice or multichoice metadata.
{
"type": "metadata",
"schema": {
"uuid": "123-123-123",
"value": ["01", "02"],
"lookup_type": "exact"
}
}
In addition, for metadata of type choice and multichoice, of subtype users, groups and dictionary_term, it is also allowed to put as "value" in the filter, the value of the uuids of the objects to be filtered by. For example:
{
"type": "metadata",
"schema": {
"uuid": "123-123-123",
"value": [<uuid_user_a>, <uuid_user_b>],
"lookup_type": "exact"
}
}
Where "uuid_user_a" and "uuid_user_b" would be the uuids of the users we want to filter by.
User type metadata
Allows filtering by user type metadata.
{
"type": "metadata",
"schema": {
"uuid": "123-123-123",
"value": ["username1", "username2"]
}
}
Metadata of type number
Allows filtering by metadata of type number.
{
"type": "metadata",
"schema": {
"uuid": "123-123-123",
"value": 1000,
"condition": ">="
}
}
Comments
0 comments
Please sign in to leave a comment.