SearchQueryBuilder

Class

SearchQueryBuilder can be used to construct the q param for searchItems or searchGroups.

By chaining methods, it helps build complex search queries.

Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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

Use dark colors for code blocksCopy
1
"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 Constructor
new SearchQueryBuilder(qstring): SearchQueryBuilder
Parameters
ParameterTypeDefaultNotes
q
string
""

An existing query string to start building from.

Returns 
SearchQueryBuilder

Methods

MethodReturnsNotes
and()

Joins two sets of queries with an AND clause.

boost(num)

Boosts the previous term to increase its rank in the results.

Returns a new instance of SearchQueryBuilder based on the current instance.

Ends a search group.

from(term)

Begins a new range query.

in(field?)

Defines fields to search in. You can pass "*" or call this method without arguments to search a default set of fields

match(terms)

Defines strings to search for.

not()

Joins two sets of queries with a NOT clause. Another option for filtering results is the prohibit operator '-'.

or()

Joins two sets of queries with an OR clause.

Starts a new search group.

to(term)

Ends a range query.

string

Returns the current query string. Called internally when the request is made.

and

Class Method
and(): SearchQueryBuilder

Joins two sets of queries with an AND clause.

Use dark colors for code blocksCopy
1
2
3
4
5
6
const query = new SearchQueryBuilder()
  .match("Lakes")
  .in("title")
  .and()
  .match("Rivers")
  .in("title")
Returns 
SearchQueryBuilder

boost

Class Method
boost(numnumber): SearchQueryBuilder

Boosts the previous term to increase its rank in the results.

Use dark colors for code blocksCopy
1
2
3
4
5
6
7
const query = new SearchQueryBuilder()
  .match("Lakes")
  .in("title")
  .or()
  .match("Rivers")
  .in("title")
  .boost(3)
Parameters
ParameterType
num
number
Returns 
SearchQueryBuilder

clone

Class Method
clone(): SearchQueryBuilder

Returns a new instance of SearchQueryBuilder based on the current instance.

Returns 
SearchQueryBuilder

endGroup

Class Method
endGroup(): SearchQueryBuilder

Ends a search group.

Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
9
10
const query = new SearchQueryBuilder()
  .startGroup()
    .match("Lakes")
    .in("title")
  .endGroup()
  .or()
  .startGroup()
    .match("Rivers")
    .in("title")
  .endGroup()
Returns 
SearchQueryBuilder

from

Class Method
from(termstring | number | Date): SearchQueryBuilder

Begins a new range query.

Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8

const NEWYEARS = new Date("2020-01-01")
const TODAY = new Date()

const query = new SearchQueryBuilder()
  .from(NEWYEARS)
  .to(TODAY)
  .in("created")
Parameters
ParameterType
term
string | number | Date
Returns 
SearchQueryBuilder

in

Class Method
in(field?string): SearchQueryBuilder

Defines fields to search in. You can pass "*" or call this method without arguments to search a default set of fields

Use dark colors for code blocksCopy
1
2
3
const query = new SearchQueryBuilder()
  .match("My Layer")
  .in("title")
Parameters
ParameterTypeNotes
field
string

The field to search for the previous match in.

Returns 
SearchQueryBuilder

match

Class Method
match(termsstring[]): SearchQueryBuilder

Defines strings to search for.

Use dark colors for code blocksCopy
1
2
const query = new SearchQueryBuilder()
  .match("My Layer")
Parameters
ParameterTypeNotes
terms
string[]

strings to search for.

Returns 
SearchQueryBuilder

not

Class Method
not(): SearchQueryBuilder

Joins two sets of queries with a NOT clause. Another option for filtering results is the prohibit operator '-'.

Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
9
10
// 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 Method
or(): SearchQueryBuilder

Joins two sets of queries with an OR clause.

Use dark colors for code blocksCopy
1
2
3
4
5
6
const query = new SearchQueryBuilder()
  .match("Lakes")
  .in("title")
  .or()
  .match("Rivers")
  .in("title")
Returns 
SearchQueryBuilder

startGroup

Class Method
startGroup(): SearchQueryBuilder

Starts a new search group.

Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
9
10
const query = new SearchQueryBuilder()
  .startGroup()
    .match("Lakes")
    .in("title")
  .endGroup()
  .or()
  .startGroup()
    .match("Rivers")
    .in("title")
  .endGroup()
Returns 
SearchQueryBuilder

to

Class Method
to(termany): SearchQueryBuilder

Ends a range query.

Use dark colors for code blocksCopy
1
2
3
4
const query = new SearchQueryBuilder()
  .from(yesterdaysDate)
  .to(todaysDate)
  .in("created")
Parameters
ParameterType
term
any
Returns 
SearchQueryBuilder

toParam

Class Method
toParam(): string

Returns the current query string. Called internally when the request is made.

Returns 
string

Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.