Filtering Using ODATA Like Statements
The main directive for filtering entities in AB Connect is the inclusion of the filter
parameter in the URL query. This document outlines how to use filtering with AB Connect. Examples are given with different endpoints and objects but the general principles are independent of the object type or endpoint. In any case, the filter limits the results that are returned or updated by the request.
At its simplest, the filtering utilizes the following syntax:
E.g. the following URL retrieves alignable 5th grade math Standards from Kentucky.
That's a bit messy so let's break it down. The first part is the primary resource endpoint.
The next bit is the filter parameter. The square brackets contain the type of object being filtered. In this case, we are limiting the Standards being returned.
The value of the filter argument is the URL encoded filter string.
Let's decode it to make it readable:
That makes it a little more readable and clarifies the intent. The specifics of the field names aren't critical here. See the endpoint specific documentation for an explanation of each field.
Constructing the Filter Statement
At an atomic level, the most common filter statement appears like <property> <comparator> '<value>'
but some functions are also supported (e.g. isempty(<property>)
).
A <property>
would be any attribute of the object being filtered. Examples of a property for a Standard would be level
or status
. Alternatively, a property can be the attribute of a complex property. E.g. for a Standard, <property>
could also be number.raw
or disciplines.subjects.code
.
A <value>
could be any value appropriate for the property in question. Values are delimited with single quotes.
Together, various operators, properties and values combine to build a logical statements. The following operators are supported by AB Connect in order of decreasing precedence by group.
Notes:
Inequality operators can be used with date, number and text attributes but the results vary by attribute type. Date attributes filter chronologically. Number attributes filter numerically. Text attributes filter alphabetically.
Custom attributes can be defined as text or numbers. If you aren't sure of the types for your custom attributes, contact AB Support for guidance.
It is possible to create custom attributes with the same name and different data types in different asset types (or when searching across multiple owners). The treatment of inequalities filtering across multiple data types is deterministic but relatively complex and isn't covered here. Where possible, we recommend you avoid this situation by ensuring your custom attributes don't have name conflicts across data types where possible. For details on the way AB Connect handles filtering across mixed types, contact AB Support.
Building Complex Statements
AB Connect also supports Boolean operations to combine atomic filter statements into complex statements. You can also use parentheses to group statements together.
disciplines.subjects.code eq 'MATH' and education_levels.grades.code eq '5'
5th grade mathdocument.publication.authorities.descr eq 'Kentucky DOE' and not disciplines.subjects.code eq 'MATH'
Standards from Kentucky not related to math(disciplines.subjects.code eq 'MATH' and education_levels.grades.code eq '5') or (disciplines.subjects.code eq 'ELA' and education_levels.grades.code eq '7')
5th grade math and 7th grade language arts Standards
Text Filters
One of the major improvements in AB Connect is the text filtering. The text filter is robust, will return results ordered by relevance and includes soft matches like partial matches. The format for text filtering is unique and utilizes a function style notation. There are two formats.
Filtering a Specific Field
When filtering a particular field, include the field name as well as the value you are filtering for: query(<field>, <string>)
. For example, to filter for Standards that contain the words "adding" and "fractions" in their statement, the filter would look like:
Note that the text filter is a very soft filter and will often return more Standards than you would expect. The results will be ordered by relevance so the top responses are usually the most important. For example, in the query statement above, the system would return Standards that contain the words "adding fractions" first, followed by Standards that contain "adding" or "fractions". It will also return Standards that contain "add", "addition", etc.
To be more specific, break phrases up into separate statements and be explicit about the Boolean operations to join the queries. The following will only return Standards if they contain both "fractions" and some form of derivation of the word "adding".
Filtering Across Multiple Text Fields
To retrieve Standards that have the keywords in any general text field, remove the field name from the query statement: query(<string>)
. E.g.
When using this approach, the system will search any fields it considers to be a text field. The specific fields vary by endpoint:
Standards:
statement.descr
statement.combined_descr
statement.addendums.descr
extensions.descr
legends.descr
Text properties on related entities as described in Filtering Resources by Properties on Related Resources
Assets:
title
Any custom attributes
Text properties on related entities as described in Filtering Resources by Properties on Related Resources
Topics:
descr
section.descr
Concepts:
descr
context
Filtering by Number in Standards
In Standards documents, numbers are often separated, delimited or decorated with symbols (e.g. "24.B (i)"). Trying to ensure users are typing the numbers EXACTLY as they are entered in the Standards document is difficult. For this reason, AB Connect supports a soft match on the Standards' number.raw
, number.enhanced
, number.prefix_enhanced
and number.root_enhanced
fields when the query function is used. It treats any separator between alphanumeric values as a break between numbers and looks for Standards that match numbers returning results by how closely they match the results. In the example listed earlier, it will return Standards that have numbers that contain 24, B AND i first without regards to the separators used in the filter. It will follow that with Standards that contain two of the three, then Standards that contain any one of the numbers. Filtering for "24.B.i" will return the same results in the same order as filtering for "24-b-i" and "24.B (i)".
Escaping Single Quotes
In ODATA, literal strings are quoted using single quotes ('). To include a single quote in a string literal in the filter, use a backslash to escape it ('). For example, to search for the word "don't" in Standards, you would use the following filter:
Checking for Empty Properties
Sometimes it is handy to search for properties that are empty. What "empty" means depends on the property type so AB Connect has an isempty
function that will match true on objects with no properties, arrays with no elements and scalar properties with null values. For example, the following filter will return all assets that are missing a subject.
Last updated