Search Results Data When Searching Within an App
When you do search within a single app there is some extra information in the search results and for each item in the search results that you can use to show how the search was performed or to augment the search result items data.
General Search Results Data
When you search an app and you specify one or more fields to sort the results or you do a filter on the search results then there are two variables available that show how the results are sorted and/or filtered.
- {#searchSort}
- {#searchFilter}
searchSort
The {#searchSort} variable holds information about how the search results were sorted.
For an example if we searched the General App and sorted by Item Name in ascending order here is what the {#searchSort} array would hold:
Array
(
[0] => Array
(
[label] => Item Name
[direction] => asc
[type] => basic
)
)
The {#searchSort} variable holds an array of information about the attributes used to sort the results. If we also searched by another field called "Disciplines" in ascending order then {#searchSort} could look like this:
Array
(
[0] => Array
(
[label] => Item Name
[direction] => asc
[type] => basic
)
[1] => Array
(
[label] => Disciplines
[direction] => asc
[type] => basic
)
)
As another example if we searched an app and used a geo location field is used to sort the search results then the {#searchSort} array would hold:
Array
(
[0] => Array
(
[label] => Single Map Point
[direction] => asc
[type] => geo
[unit] => mi
[lat] => 60
[lon] => 47
)
)
When a geo sort is done the array also holds the latitude and longitude used for doing the sort.
searchFilter
The {#searchFilter} variable holds an array of information about the attributes used to filter the search results. Right now the only search filters are geo location filters.
If we were to use a geo location filter for a field called "Map Point" and limited results to be within 500 miles of 60° latitude and 47° longitude then the {#searchFilter} array will look like this:
Array
(
[0] => Array
(
[label] => Map Point
[options] => Array
(
[lat] => 60
[lon] => 47
[distance] => 500
[unit] => mi
)
[type] => geoDistance
)
)
Search Results Item Data
When you search an app the individual search results are essentially the same information that you would get if you were displaying a list of items for the app home page or item list pages. There are a few extra pieces of information put in the item's array of data that pertain to the search results.
- searchContent
- searchData
searchContent
Within search results, each item that is included in the results will have a "searchContent" value in the item array. The content usually comes from a default description attribute for the app item. For example, in the General app the value would come from the default "Description" attribute. In the Store app the value would come from the default product "Description" attribute.
The "searchContent" value is a string value.
Any part of the "searchContent" which matches a general query will be wrapped in <strong> tags.
searchData
The 'searchData' value is an array of information that could hold information of how the individual item was sorted. It can be populated when a geo location field is used to sort the search results or it can be populated if sorting by relevancy is specified.
For an example lets say that we have a Map Latitude & Longitude attribute called "Map Point" with a layout key of "mapPoint"
Below is an example of 'searchData' for a search results item if we sorted by geo location with the 'mapPoint' attribute.
Array
(
[sort] => Array
(
[singleMapPoint] => 418.9722784054
)
[distance] => 418.9722784054
[distanceUnit] => mi
)
Within the 'searchData' array is a 'sort' value that holds an array of attribute layout keys and the distance that that search result item is from the submitted 'mapPoint' latitude and longitude values. The distance defaults to miles but it can be changed to kilometers by specifying the 'unit' when searching. See Sort by Geo Location for more information.
To make it a little easier to get the distance information you can also access it directly through the 'distance' and 'distanceUnit' values.
If you specify sorting by relevancy then the score information will show in this array.
Array
(
[sort] => Array
(
[_score] => 0.5066428
)
)