Using filter operators (<, >, <=, >=, or) in Directus - directus

I want to filter with these specific operators:
- "<", ">", "<=", ">=" for integer and date values.
- "or" for text fields.
PS: my question concerns the admin backend UI not the underlying API.

This has been added in the last major release of Directus (v7)

Related

Lucene operator precedence for boolean operators

What is the order of operations for boolean operators? Left to right? Right to left? Specific operators have higher priority?
For example, if I search for:
jakarta OR apache AND website
What do I get? Is it
Anything with "jakarta" as well as anything with both "apache" and "website"?
Anything with "website" that also has either "jakarta" or "apache"?
Something else?
Short answer:
In Lucene, the AND operator takes precedence over the OR operator. So, you are effectively doing this:
jakarta OR (apache AND website)
You can verify this for yourself by parsing your query string and seeing how it converts AND and OR to the "required" and "optional" operators.
And the NOT operator takes precendence over the AND operator, since we are discussing precedence.
But you need to be very careful when dealing with Lucene's so-called "boolean" operators, as they do not behave the way you may expect based on their collective name ("boolean").
(Unfortunately I have never seen any official documentation which provides a citation for these precedence rules - but instead I am relying on empirical observations. See below for more about that. If the documentation for this does exist, that would be great to see.)
Longer Answer
One key thing to understand is that Lucene boolean operators are not really "boolean" in the sense that you may think, based on Boolean algebra, where you use parentheses to help avoid ambiguity (or where you need to know what rules a programming language may be applying) - and where everything evaluates to TRUE or FALSE.
Lucene boolean operators serve a subtly different purpose.
They are not purely concerned with TRUE/FALSE inclusion/exclusion, but also concerned with how to score results so that the more relevant results have higher scores than less relevant results.
The Lucene query jakarta OR apache AND website is equivalent to the following:
jakarta +apache +website
This means the document's field must contain apache and website, but may also include jakarta (for a higher relevance score).
You can see this for yourself by taking your original query string and parsing it:
Query query = parser.parse(queryString);
...and then printing the resulting string representation of the query. The + operator is the "required" operator. It:
requires that the term after the "+" symbol exist somewhere in the field
And the lack of a + operator means the default of "may" as in "may contain" - meaning the term is optional: it does not need to be present, if there is some other clause in the query which does match a document.
The use of AND forces the terms on either side of the AND to be required.
You can encounter some potentially surprising situations.
Consider this:
foo AND bar OR baz AND bat
This parses to the following:
+foo +bar +baz +bat
This is because the AND operators are transformed to + operators for every term, rendering the OR redundant.
It's the same result as if you had written this:
foo AND bar AND baz AND bat
But not the same as this:
(foo AND bar) OR (baz AND bat)
which is parsed to this, where the parentheses are retained:
(+foo +bar) (+baz +bat)
Bottom Line:
Use parentheses to explicitly make your intentions clear, when using AND and OR and also NOT.
Regarding NOT, since we mentioned it - that takes prescendence over AND.
The query:
foo AND bar NOT baz AND bat
Is parsed as:
+foo +bar -baz +bat
So, a document field must contain foo, bar and bat - and must not contain baz.
Why does this situation exist?
I don't know, but I think Lucene originally did not include AND, OR and NOT - but instead used + (must include), - (must not include) and "nothing" (may include). The so-called boolean operators AND, OR, NOT were added later on, as a kind of "syntactic sugar" for these original operators - introduced for people who were more familiar with AND, OR and NOT from other contexts. I'm basing this on the following thread:
Getting a Better Understanding of Lucene's Search Operators
A summary of that thread is included in this answer about the NOT operator.

why contains keyword is not working on rally api query

I am trying to query on rally api by using below
req.Query = new Query("User.ObjectID", Query.Operator.Equals, loggedinUser.ToString()).And(new Query("Role", Query.Operator.Contains, Role).And(new Query("Workspace.ObjectID", Query.Operator.Contains, workspaceID)).And(new Query("Project.ObjectID", Query.Operator.Equals, projectObjectID)));
But it is throwing error as
The operator [ contains ] is not supported for this attribute type. The available operators are [ =, !=, >, <, >=, <=, in ]
is it contains key word is deprecated? please help me alternative in such case.
You can't use contains for an object id- that attribute is numeric. contains is reserved for strings and collections.
It's the Workspace.ObjectID specifically that's ruining your day. Change it to equals and you should be good to go.
As per
https://communities.ca.com/thread/241816885-why-contains-keyword-is-not-working-on-rally-api-query?et=watches.email.outcome
contains no longer supports in such type of queries but previously it is worked.
Its working when I replaced 'Contains' with 'Equals' as
req.Query = new Query("User.ObjectID", Query.Operator.Equals, loggedinUser.ToString()).And(new Query("Role", Query.Operator.Equals, Role).And(new Query("Workspace.ObjectID", Query.Operator.Equals, workspaceID)).And(new Query("Project.ObjectID", Query.Operator.Equals, projectObjectID)));

Population of a selection box base on the Other Selection Box

Good Day! I have a problem I am trying to populate a Selection box base on the selected data on the other selection box here is my code
.py
licensetype = fields.Many2one('hr.licensetype','License Type')
license = fields.Many2one('hr.license','License')
#api.one
#api.onchange('licensetype')
def getlicense(self):
if len(self.licensetype) > 0:
mdlLicense= self.env['hr.license'].search([('license_name', '=', int(self.licensetype[0]))])
#raise Warning(mdlLicense.ids)
self.license = mdlLicense.ids
but still it populate all license I want to populate the License based on the selected License type. This is in Odoo8
Domains
A domain is a list of criteria, each criteria being a triple (either a list or a tuple) of (field_name, operator, value).
Here,
field_name :
It's string type and must be from the current model or any relational traversal field through the Many2one/One2many field using membership (.) dot operator.
- operator : It's for comparing field's value with passed value.
Valid operator list (>, >=, <, <=, =, !=, =?, ilike, like =like, =ilike, not like, not ilike, childs_of, in, not in)
value : It's for comparing with field's value.
Multiple criteria can be joined with three logical operators.
Logical AND, logical OR, logical NOT.
Read more about domain
You can easily achieve this by defining domain for that field, no need to write any extra code.
Just put domain in your xml code.
<field name="licensetype" />
<field name="license" domain="[('licensetype','=',licensetype)]" />
Note :
Remember there must be relation between hr.license and hr.licensetype. licensetype must be Many2one in hr.license.
It will give the same effect as you want.

How to filter by dateHour on Google Analytics API?

I'm trying to retrieve results from the Google Analytics API that are between two specific dateHours. I tried to use the following filter:
'filters' => 'ga:dateHour>2013120101;ga:dateHour<2013120501'
But this doesn't work. What do I need to do? (I've used other filters before, and they work just fine).
First off, you're trying to use greater than and less than on a dimension which doesn't work. Dimension filters only allow ==, !=, =#, !#,=~, and !=.
So, if you want to get ga:dateHour, you'll have to use a regex filter:
ga:dateHour=~^2013120([1-4][0-2][0-9]|500)$;ga:dateHour!~^201312010[0-1]$
EDIT:
I wouldn't hesitate a second to learn RegEx, especially if you're a programmer. Here is a great SO post on learning regular expressions.
So, to break it down:
=~ looking to match the following regex
!= not looking to match the following regex
(check out GA's filter operators)
^ at the start of a string
2013120 since the entire dateHour range contained this string of numbers, look for that
([1-4][0-2][0-9]|500) match every number after 2013120, so the first [1-4] will match 20131201, 20131202, 20131203, and 20131204, then within those strings we want the next number to be [0-2] and likewise with [0-9]. So look at each [ ] as a placeholder for a range of digits.
| means or
500 says, we only want 500 and nothing more, so it's very specific.
The whole statement is wrapped in () so we can say he, match [1-4][0-2][0-9] OR 500, after 2013120.
Then, we end it with $ to signify the end of the string.
This probably isn't the most concise way to describe how this filter is working, but what I would do is use a website like regexpal or some other regex testing tool, and get the range you'd like to filter and start writing regex.
Best of luck!

SQL from where like with or statement

I have a SQL statement to search for an application by name.
def apps = Application.findAll("from Application as app where lower(app.name) like '%${params.query.toLowerCase()}%' ")
I want to not just be able to search by the applications name, but by different properties such as type and language. How would I add or statements to allow me to do this. Thanks!
It's not clear (to me) what framework you're using, or what specific RDBMS your database is on, but the overall thrust of SQL conditions is usually pretty simple.
Pretty much, like most other computer languages, you use and/or/not statements. Of course, in SQL you use the words, instead of (what are usually) symbols:
AND instead of &&
OR instead of ||
NOT instead of !
along with the standard comparison operators:
<, <=, =, <>, >, >=
Note that 'equals' is only a single = sign, and 'not equals' is usually opposed angle brackets <>.
So, given your current statement, if you wanted to only get those applications in the user's language, and exclude apps that are 'disabled', you could do something like the following:
def apps = Application.findAll("from Application as app
where lower(app.name) like '%${params.query.toLowerCase()}%'
and app.language = userLanguageParameter
and app.status <> inactiveAppStatus ");