SearchQueryBuilder
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 Parameters
Methods
Method | Returns | Notes |
---|---|---|
| SearchQueryBuilder | Joins two sets of queries with an |
| SearchQueryBuilder | Boosts the previous term to increase its rank in the results. |
| SearchQueryBuilder | Returns a new instance of |
| SearchQueryBuilder | Ends a search group. |
| SearchQueryBuilder | Begins a new range query. |
| SearchQueryBuilder | Defines fields to search in. You can pass |
| SearchQueryBuilder | Defines strings to search for. |
| SearchQueryBuilder | Joins two sets of queries with a |
| SearchQueryBuilder | Joins two sets of queries with an |
| SearchQueryBuilder | Starts a new search group. |
| SearchQueryBuilder | Ends a range query. |
| string | Returns the current query string. Called internally when the request is made. |
and
Returns
const query = new SearchQueryBuilder() .match("Lakes") .in("title") .and() .match("Rivers") .in("title")
boost
Boosts the previous term to increase its rank in the results.
Parameters
Returns
const query = new SearchQueryBuilder() .match("Lakes") .in("title") .or() .match("Rivers") .in("title") .boost(3)
endGroup
Ends a search group.
Returns
const query = new SearchQueryBuilder() .startGroup() .match("Lakes") .in("title") .endGroup() .or() .startGroup() .match("Rivers") .in("title") .endGroup()
from
Begins a new range query.
Parameters
Returns
const NEWYEARS = new Date("2020-01-01") const TODAY = new Date() const query = new SearchQueryBuilder() .from(NEWYEARS) .to(TODAY) .in("created")
in
Defines fields to search in. You can pass "*"
or call this method without arguments to search a default set of fields
Parameters
Returns
const query = new SearchQueryBuilder() .match("My Layer") .in("title")
match
Defines strings to search for.
Parameters
Returns
const query = new SearchQueryBuilder() .match("My Layer")
not
Joins two sets of queries with a NOT
clause. Another option for filtering results is the prohibit operator '-'.
Returns
// 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")
or
Joins two sets of queries with an OR
clause.
Returns
const query = new SearchQueryBuilder() .match("Lakes") .in("title") .or() .match("Rivers") .in("title")
startGroup
Starts a new search group.
Returns
const query = new SearchQueryBuilder() .startGroup() .match("Lakes") .in("title") .endGroup() .or() .startGroup() .match("Rivers") .in("title") .endGroup()
to
Ends a range query.
Parameters
Returns
const query = new SearchQueryBuilder() .from(yesterdaysDate) .to(todaysDate) .in("created")
toParam
Returns the current query string. Called internally when the request is made.
Returns
Class defined in packages/arcgis-rest-portal/src/util/SearchQueryBuilder.ts:46
Joins two sets of queries with an
AND
clause.