Sorting data on the basis of a function value
Suppose we have a search application that stores information about companies. Every company is described by a name and two floating point numbers that represent the geographical location of the company. One day your boss comes to your room and says that he wants the search results to be sorted by distance from the user's location. What's more, he wants us to force our search engine to return the distance from a user location to each of the returned companies. This recipe will show you how to achieve this requirement.
How to do it...
Let's perform the following steps to sort data on the basis of a function value:
For this recipe, we will begin with the following index structure (add the following entries to your
schema.xml
file):<field name="id" type="string" indexed="true" stored="true" required="true" /> <field name="name" type="text_general" indexed="true" stored="true"/> <field name="location" type="location" indexed="true" stored...