Modifying geo-spatial parameters in the data model

Table of Contents


This article demonstrates how to set or modify geo-spatial parameters in the data model (origin, maxdist).


Geospatial search constraints are controlled using the origin and maxdist parameters.

origin and maxdist parameters are populated before the pre-process hook script runs.

This means that they can not be modified in the inputParameterMap (or rawInputParameters) in any of the available hook scripts.

To modify these values you need to set them in the additionalParameters structure.

def q = transaction.question
def near = 50 // Default 'near' value (km)
def geoRadiusThresholdPercentage = 200 // Increase maxdist radius by a particular threshold
if (q.inputParameterMap["maxdist"] != null) {
    // Store original for visualisation
    transaction.response.customData["maxdist_original"]    = q.inputParameterMap["maxdist"]

    // Increase maxdist by threshold
    transaction.response.customData["maxdist_modified"]    = (q.inputParameterMap["maxdist"].toFloat() * (geoRadiusThresholdPercentage/100)).toString()

    // Increase maxdist before processing
    q.dynamicQueryProcessorOptions.add("-maxdist=" + transaction.response.customData["maxdist_modified"])
    q.additionalParameters["maxdist"] = transaction.response.customData["maxdist_modified"]
else {
    // Use 'near' distance instead
    // q.dynamicQueryProcessorOptions.add("-maxdist=" + near)
    // q.additionalParameters["maxdist"] = near
// Set default sort order to geospatial proximity if using map/geojson form and origin available
if (((q.inputParameterMap["form"] == "map") || (q.inputParameterMap["form"] == "geojson"))
        && (q.inputParameterMap["origin"] != null)) {
    q.inputParameterMap["sort"] = "prox"
def q = transaction.question
if (q.inputParameterMap["maxdist"] != null) {
    // Restore maxdist to original value
    q.inputParameterMap["maxdist"] = transaction.response.customData["maxdist_original"]