Advance/Query Builder Search

To let end users create complex search queries Asta7 offers a query builder or advanced search. Instead of a fixed advanced search users can create searches/filters of their own using a simple UI.

image-20240220-094948.png

User Stories

https://stiftelsenasta.atlassian.net/wiki/spaces/AO/pages/1634598936

Classes

FilterSearch

This is the root class that saves queries against a user. It is also possible to make a filter global.

QueryGroup

This is used to group multiple queries. Based on the group condition it can either be grouped as an AND query or an OR query. A query group can contain multiple query groups or query rules.

QueryRule

This is used to link the query field, query operator, and user-provided value. It is also possible to negate the query using the negate property of this class.

QueryOperator

This is what generates individual ES queries like query_string, term, range, etc. It uses the query field and user-provided value and converts them to the appropriate ES query. For example, the ContainsQueryOperator of TextQueryField generates an ES query_string query with wildcards at both ends.

QueryField

This class holds information about the actual ES field (name, label, nested path, etc.).

SortRule

This is used for generating sorting rules with field names and order. There can be multiple sorting rules.

How to operate

For every query in the filter, the user has to select a field first. Similar to the basic mode tree select a dropdown of all the available fields will be available for every rule to select the field. Then based on the selected field a list of operators will appear, and based on the selected operator an appropriate value field will be shown.

Fields and Operators

Operators are dependent on fields and field types. Below is the list of all the current operators available:

Every operator can be negated with the not operator. All the text queries are case insensitive.

Field Type

Operator

Description

Field Type

Operator

Description

any

exists

Has value.

varchar/text/uuid

equals

Has value that equals the provided value ignoring the case.

varchar/text

matches

Has any token/word matching the provided value.

varchar

contains

Has value containing the provided value.

 

starts with

Has value that starts with the user provided value.

 

ends with

Has value that ends with the user provided value.

 

greate than

Has value that is greater than the provided value alphanumerically and ignoring the case.

 

greate than equals

Has value that is greater than or equal to the provided value alphanumerically and ignoring the case.

 

less than

Has value that is less than the provided value alphanumerically and ignoring the case.

 

less than equals

Has value that is less than or equals to the provided value alphanumerically and ignoring the case.

 

between

Has value that is greater than or less than the provided value alphanumerically and ignoring the case.

integer/float/serial/date/timestamp

equals

Has value that equals the provided value. (Including time in case of timestamp)

 

greate than

Has value that is greater than the provided value.

 

greate than equals

Has value that is greater than or equal to the provided value.

 

less than

Has value that is less than the provided value.

 

less than equals

Has value that is less than or equals to the provided value.

 

between

Has value that is greater than or less than the provided value.

boolean

yes

Has TRUE value.

 

no

Has FALSE value.

codeTableRef fields

in

Has value that equals to any of the provided set of values.

Digital file content field (a text field)

matches

Has any token/word matching the provided value.

Grouping

Rules can be divided into any number of groups. It is also possible to nest groups in any way needed. For each group, the group condition (AND/OR) can also be selected.

When generating the ES query all the rules in a group will be combined in the ES bool query. Furthermore, all the rules with the same or matching nested paths will be grouped in the same ES nested query. This makes sure that multiple rules can be added for a nested level or its sub-levels.

For example, If the group contains the following rules

Nested Path

Field

Operator

Value

Nested Path

Field

Operator

Value

serie

serie.identifikator

equals

A

serie

serie.navn

starts with

Oslo

serie.stykke

serie.stykke.startdato

greater than

1920

serie.stykke

serie.stykke.slutdato

less than

1950

serie.stykke.mappe

serie.stykke.mappe.navn

matches

Test

An ES query like the following would be generated

{ "bool": { "must": [{ "nested": { "path": "serie", "query": { "bool": { "must": [{ "term": { "serie.identifikator": "A" } }, { "wildcard": { "serie.navn": "Oslo*" } }, { "nested": { "path": "serie.stykke", "query": { "bool": { "must": [{ "range": { "serie.stykke.startdato": { "gt": "1920" } } }, { "range": { "serie.stykke.slutdato": { "lt": "1950" } } }, { "nested": { "path": "serie.stykke.mappe", "query": { "match": { "serie.stykke.mappe.navn": { "query": "Test" } } } } }] } } } }] } } } }] } }