Skip to main content
Version: 2025.1

SpatialSearchExtension

Extension for an IndexQuery to carry out a spatial search using the index. The configuration object serves as an extension for an existing IndexQuery and offers the possibility to filter and score results according to distance. The search is always based on the specified center point (required) and the distance in km (default 25). The default method is SPATIAL_METHOD_RADIUS Unless otherwise defined, the search is carried out on the #LOCATION ('location') system field of the index.

Methods​

getCenterPoint​

getCenterPoint(): number[]

Returns​

number[]

the specified center point (lat,lon) for the spatial search as an array, or null if not specified.


getDistance​

getDistance(): number

Returns​

number

the searched distance in km used for spatial search. Default is 25km.


getLocationEntityField​

getLocationEntityField(): string

Returns the entity field whose index field is used for spatial search. IMPORTANT: The index field must have the index field type LOCATION!

Returns​

string

The entity field whose index field is used for spatial search or null if not specified.


getLocationField​

getLocationField(): string

Returns the index field used for spatial search. If not specified, the system field #LOCATION ('location') is used. IMPORTANT: The field must have the index field type LOCATION!

Returns​

string

The index field used by the spatial search or null if not specified.


getMethod​

getMethod(): string

Returns​

string

The spatial search method that is used. Default: SPATIAL_METHOD_RADIUS


isBoostNearestResults​

isBoostNearestResults(): boolean

Returns​

boolean

true if the score of a document should be higher depending on its proximity to the specified center point.


isFilterResults​

isFilterResults(): boolean

Returns​

boolean

true (default), if only documents within the specified distance should be included in the result.


setBoostNearestResults​

setBoostNearestResults(pBoostNearestResults): SpatialSearchExtension

Parameters​

pBoostNearestResults
boolean

true if the score of a document should be higher depending on its proximity to the specified center point.

Returns​

SpatialSearchExtension

setCenterPoint​

setCenterPoint(pLat, pLon): SpatialSearchExtension

Sets the center point (lat,lon) for the spatial search.

Parameters​

pLat
number

The latitude of the center point.

pLon
number

The longitude of the center point.

Returns​

SpatialSearchExtension

setDistance​

setDistance(pDistance): SpatialSearchExtension

Sets the distance in km used for spatial search. Default is 25km.

Parameters​

pDistance
number

the distance in km.

Returns​

SpatialSearchExtension

setFilterResults​

setFilterResults(pFilterResults): SpatialSearchExtension

Specifies whether only documents within the specified distance should be included in the result. Default is true

Parameters​

pFilterResults
boolean

true (default), if only documents within the specified distance should be included in the result.

Returns​

SpatialSearchExtension

setLocationEntityField​

setLocationEntityField(pLocationEntityField): SpatialSearchExtension

Sets the entity field whose index field is used for spatial search. If not specified, the system field #LOCATION invalid input: '<'/ tt> ('_location_') is used. **IMPORTANT:** The index field must have the index field type &lt;var&gt;LOCATION&lt;/var&gt;!

Parameters​

pLocationEntityField
string | number | boolean

the name of the entity field.

Returns​

SpatialSearchExtension

setLocationField​

setLocationField(pLocationField): SpatialSearchExtension

the index field used for spatial search. If not specified, the system field #LOCATION ('location') is used. IMPORTANT: The field must have the index field type LOCATION!

Parameters​

pLocationField
string | number | boolean

the index field used by the spatial search.

Returns​

SpatialSearchExtension

setMethod​

setMethod(pMethod): SpatialSearchExtension

Sets the search method of the spatial search. Possible values are indexsearch.SPATIAL_METHOD_RADIUS and indexsearch.SPATIAL_METHOD_BOX

Parameters​

pMethod
string | number | boolean

The search method used for spatial search.

Returns​

SpatialSearchExtension

Example​

var spatialExt = indexsearch.createSpatialSearchExtension() .setMethod(indexsearch.SPATIAL_METHOD_RADIUS) // setting the search method (default: radius) .setCenterPoint(50.0, 50.0) // setting the center point (required!) .setDistance(10.0) // setting a new distance in km (default: 25) .setFilterResults(true) // enable / disable filtering of results outside the given distance (default: true) .setBoostNearestResults(false); // enable / disable scoring of results by distance (default: true) var query = indexsearch.createIndexQuery().addExtension(spatialExt); // adding the extension to an index query indexsearch.searchIndex(query);