Suppose we have a search application that is storing information about the 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/she wants the search results to be sorted by distance from the user's location. This recipe will show you how to do it.
Before continuing please read the Storing geographical points in the index recipe from Chapter 3, Analyzing Your Text Data.
Let's begin with the following index (add the following to your
schema.xml
file to thefields
section):<field name="id" type="string" indexed="true" stored="true" required="true" /> <field name="name" type="text" indexed="true" stored="true"/> <field name="location" type="location" indexed="true" stored="true" /> <dynamicField name="*_coordinate" type="tdouble" indexed="true" stored="false" />
We also...