Class
SearchQueryBuilder
can be used to construct the q
param for searchItems
or searchGroups
.
By chaining methods, it helps build complex search queries.
const startDate = new Date("2020-01-01");
const endDate = new Date("2020-09-01");
const query = new SearchQueryBuilder()
.match("Patrick")
.in("owner")
.and()
.from(startDate)
.to(endDate)
.in("created")
.and()
.startGroup()
.match("Web Mapping Application")
.in("type")
.or()
.match("Mobile Application")
.in("type")
.or()
.match("Application")
.in("type")
.endGroup()
.and()
.match("Demo App");
searchItems(query).then((res) => {
console.log(res.results);
});
Will search for items matching
"owner: Patrick AND created:[1577836800000 TO 1598918400000] AND (type:"Web Mapping Application" OR type:"Mobile Application" OR type:Application) AND Demo App"
Implements
Constructors
constructor
Class Constructornew SearchQueryBuilder(q: string): SearchQueryBuilder
Parameters
Parameter | Type | Default | Notes |
---|---|---|---|
q | string | "" | An existing query string to start building from. |
Returns
SearchQueryBuilder
Methods
Method | Returns | Notes |
---|---|---|
and() | Joins two sets of queries with an | |
boost(num) | Boosts the previous term to increase its rank in the results. | |
clone() | Returns a new instance of | |
endGroup() | Ends a search group. | |
from(term) | Begins a new range query. | |
in(field?) | Defines fields to search in. You can pass | |
match(terms) | Defines strings to search for. | |
not() | Joins two sets of queries with a | |
or() | Joins two sets of queries with an | |
Starts a new search group. | ||
to(term) | Ends a range query. | |
toParam() | string | Returns the current query string. Called internally when the request is made. |
and
Class Methodand(): SearchQueryBuilder
Joins two sets of queries with an AND
clause.
const query = new SearchQueryBuilder()
.match("Lakes")
.in("title")
.and()
.match("Rivers")
.in("title")
Returns
SearchQueryBuilder
boost
Class Methodboost(num: number): SearchQueryBuilder
Boosts the previous term to increase its rank in the results.
const query = new SearchQueryBuilder()
.match("Lakes")
.in("title")
.or()
.match("Rivers")
.in("title")
.boost(3)
Parameters
Parameter | Type |
---|---|
num | number |
Returns
SearchQueryBuilder
clone
Class Methodclone(): SearchQueryBuilder
Returns a new instance of SearchQueryBuilder
based on the current instance.
Returns
SearchQueryBuilder
endGroup
Class MethodendGroup(): SearchQueryBuilder
Ends a search group.
const query = new SearchQueryBuilder()
.startGroup()
.match("Lakes")
.in("title")
.endGroup()
.or()
.startGroup()
.match("Rivers")
.in("title")
.endGroup()
Returns
SearchQueryBuilder
from
Class Methodfrom(term: string | number | Date): SearchQueryBuilder
Begins a new range query.
const NEWYEARS = new Date("2020-01-01")
const TODAY = new Date()
const query = new SearchQueryBuilder()
.from(NEWYEARS)
.to(TODAY)
.in("created")
Parameters
Parameter | Type |
---|---|
term | string | number | Date |
Returns
SearchQueryBuilder
in
Class Methodin(field?: string): SearchQueryBuilder
Defines fields to search in. You can pass "*"
or call this method without arguments to search a default set of fields
const query = new SearchQueryBuilder()
.match("My Layer")
.in("title")
Parameters
Parameter | Type | Notes |
---|---|---|
field | string | The field to search for the previous match in. |
Returns
SearchQueryBuilder
match
Class Methodmatch(terms: string[]): SearchQueryBuilder
Defines strings to search for.
const query = new SearchQueryBuilder()
.match("My Layer")
Parameters
Parameter | Type | Notes |
---|---|---|
terms | string[] | strings to search for. |
Returns
SearchQueryBuilder
not
Class Methodnot(): SearchQueryBuilder
Joins two sets of queries with a NOT
clause. Another option for filtering results is the prohibit operator '-'.
// omit results with "Rivers" in their title
const query = new SearchQueryBuilder()
.not()
.match("Rivers")
.in("title")
// equivalent
const query = new SearchQueryBuilder()
.match("Rivers")
.in("-title")
Returns
SearchQueryBuilder
or
Class Methodor(): SearchQueryBuilder
Joins two sets of queries with an OR
clause.
const query = new SearchQueryBuilder()
.match("Lakes")
.in("title")
.or()
.match("Rivers")
.in("title")
Returns
SearchQueryBuilder
startGroup
Class MethodstartGroup(): SearchQueryBuilder
Starts a new search group.
const query = new SearchQueryBuilder()
.startGroup()
.match("Lakes")
.in("title")
.endGroup()
.or()
.startGroup()
.match("Rivers")
.in("title")
.endGroup()
Returns
SearchQueryBuilder
to
Class Methodto(term: any): SearchQueryBuilder
Ends a range query.
const query = new SearchQueryBuilder()
.from(yesterdaysDate)
.to(todaysDate)
.in("created")
Parameters
Parameter | Type |
---|---|
term | any |
Returns
SearchQueryBuilder