Location

Overview

Location-Based Search enhances the SearchStax Site Search experience by using location data to return the most geographically relevant results, sorted, filtered, or boosted by proximity to the search user.

Location-Based Search is a Profile-level feature when your App has multiple Search Profiles. You can configure Location settings independently for each profile or apply changes across multiple profiles. See Multi-Site Search Management for details.

The benefits of location search are analyzed in our blog, Unlocking Better User Experiences with Location Search.

Add-On Feature

This is an optional feature that can be added to your SearchStax account. Contact support for details.

Location via Search API

You can submit location-based queries directly from the Search API.

Location Inputs

Location matching calculates the distance between a search user and various objects represented in the Solr index. To make this calculation, it requires two kinds of inputs:

  • Users must provide their zip code or city name when framing a query to establish their location. A field for these values is provided on the Hosted Search Experience
    Location search bar with Manhattan Beach, CA 90264 entered, featuring a
  • The index records must contain decimal latitude and longitude coordinates for each locatable object in a form similar to "location_p": "34.0629,-118.3581". The field must be a solr.LatLonPointSpatialField. You can achieve this in Site Search by appending the _p dynamic field type suffix to the field name before uploading the data. For Drupal, use the locs_ prefix.

Location Search Features

Location-based logic can be applied in these ways:

Distance can be configured in miles or in kilometers.

Enable Location Features

Go to Site Search > Configurations > Advanced Configurations > Location.

Location configuration panel with enable toggle, location field dropdown set to location_p, distance unit dropdown set to Miles, and option to add locat...

To enable location-based search features:

  1. Engage the Enable Location toggle.
  2. Select the Location Field (the field that contains the latitude/longitude data). If you don’t see the field in the droplist, click the Reload Schema button. 
    The Location Field with a Reload Schema button displayed on hover.
  3. Indicate Distance Units (miles or kilometers).
  4. Optionally, enable a Location Results Field. This option adds lat/long values to the search results to support custom map-based UI features in your search page. 
    JSON response showing location coordinates highlighted in the location_p field with latitude and longitude values.

    It also automatically maps this field to an invisible Location field on the Hosted Search Experience results card
    Location field configuration showing location_p mapped to Location label with move controls.The invisible field hides the lat/long data from casual viewers while leaving it programmatically available to front-end developers. To make the lat/long values visible, remove the Location mapping from the field!

Remember to Publish your changes before you leave the page.

Distance Results Field

Site Search can optionally include a Distance field in the search results, showing the distance (in miles or kilometers) between the search user’s location and the matching item:

The Enable Distance Results Field toggle switch in the off position with explanatory text about adding distance values to search results cards.

This field is automatically named after the lat/long field with an added _distance suffix, as in location_p_distance. Setting the toggle automatically adds this field to the Results Fields.

Location distance field in search results displaying 12.458344 miles between user and matching item.

Field mapping configuration showing location_p_distance mapped to the Distance label.

The value appears among the “unmapped” fields at the bottom of the Hosted Search Experience result item:

Location distance indicator showing 12 miles from Beverly Blvd & Robertson Blvd.

Note that the field will not appear until the user enters a location (zip code or city name) on the search page.

Results Without Lat/Long Data

Result items that lack position data return a calculated distance of “Infinity”. The Hosted Search Experience and the Preview screen suppress this result, showing no distance value.

Distance Filtering

The Distance Filter feature excludes matching documents that are more than a specific distance from the search user. When this feature is enabled, the Hosted Search Experience offers a dropdown list of search radii to select from.

Distance filter dropdown menu with options ranging from any distance to 100 miles, with 25 miles selected as the default.

To enable and configure this feature from the Location screen:

Distance Filter configuration panel with enable toggle, label field, distance input, and preset distance options ranging from any distance to 100 miles.

  1. Engage the Enable Distance Filter toggle.
  2. Enter a Distance Filter Label. This label appears only in the search-results metadata, for the convenience of your search page developers:
    The Distance filter configuration showing label and values parameters with distance options in kilometers.
  3. The remainder of the controls manage the dropdown menu of search radii. “Any Distance” must always be present, but you can add or remove other options to suit your use case.
    • To add an option, enter the desired distance and click the (+) button.
    • To remove an option, click the (x) button beside it.
    • Use the radio buttons to choose one option as the default.

Remember to Publish the changes.

Distance-Based Boosting

The Distance-Based Boost feature is a ranking multiplier on the partial score contributed by the Distance field. This is an inverse multiplier, meaning that small distances are boosted more than large ones.

Enable the feature using the Enable Distance-Based Boost toggle on the Location screen:

Toggle switch for enabling distance-based boost ranking to prioritize search results by location proximity.

When enabled, a boost control for the Distance field appears automatically on the Ranking screen:

Ranking boost configuration panel with distance_boost function set to a boost value of 1.

If this boost is in the Main Profile (the default), the Ranking Boost multiplier is automatically set to 1. If not, the Boost multiplier is set to 0. You can adjust the boost as you wish.

Remember to Publish your changes.

Distance-Based Sorting

Distance-Based Sorting is the simplest of the Location-Based Search features. It sorts search results according to the inverse of the Distance field, so nearby results are at the top of the list.

Use the Enable Distance-Based Sorting toggle to activate this feature.

Distance-Based Sorting toggle control with description of how proximity sorting orders search results by location.

When enabled, this feature adds a geodist() sorting function to the Sorting screen and labels it “Distance.” This becomes one of the sorting options on the Hosted Search Experience.

The sorting configuration interface showing geodist() function with Ascending sort order and Distance label, plus a dropdown menu displaying Sort By opt...

If you’d like to sort in the opposite direction, change Ascending to Descending.

Articles in this section