Let's imagine that you have an application that allows the user to search through the companies that are stored in the index. You would like to add an additional feature to your application to sort the results on the basis of the distance of a certain geographical point. Is this possible with Solr? Yes, and this recipe will show you how to do that.
The following recipe uses spatial search. If you are not familiar with geographical search in Solr please read the Storing geographical points in the index recipe in Chapter 3, Analyzing Your Text Data.
Let's start with the following index structure (just add this to your
schema.xml
file, to thefield
section):<field name="id" type="string" indexed="true" stored="true" required="true" /> <field name="name" type="text" indexed="true" stored="true" /> <field name="geo" type="location" indexed="true" stored="true" /> <dynamicField name="*_coordinate" type="tdouble...