Filtering
Filter your results
Parameters
Filtering the results is controlled by the filter
parameter. This parameter expects a SQL-like formatted string that describes the filtering rules.
Check below for more info.
Name
Type
Is Required ?
Default value
filter
string
✖
empty string
filter
filter
Filter the results using an SQL-like syntax. The generic syntax is as follows:
filterRule: `${attribute} ${rule_operator} ${value}`
filterGroup: `(${filterRule1} ${group_operator} ${filterRule2} ...)`
rule_operator: =, !=, <, <=, >, >=
group_operator: AND, OR
filter
can be either a single filterRule
or a filterGroup
.
For example, all the following filters are valid:
size = 137
size != 137
price > 50
(size = 137)
(size = 137 OR size = 133 OR size = 48)
price >= 10 AND price < 100
(size = 137 OR size = 119) AND (price > 10 AND price < 100)
size = 137 OR price > 10
size = 137 AND price > 10
Response
All responses from XO Search uses the same format. Check API Reference page for a more detailed description of this format.
API ReferenceUsage examples
Filter results with a price higher than 10 €
NodeJS / NPM example
import { search } from '@attraqt/search';
const query = 'T-shirt';
search.init({ token: SEARCH_API_TOKEN });
const response = await search.query(query, {
filter: 'price > 10'
});
console.log(response);
HTML example
<script type="text/javascript">
xo.init({
search: {
token: SEARCH_API_TOKEN
}
});
xo.search.query('T-Shirt', {
filter: 'price > 10'
}).then((response) => {
console.log(response);
});
</script>
Last updated