|
15 | 15 | from haystack.query import RelatedSearchQuerySet, SearchQuerySet, SQ
|
16 | 16 | from haystack.utils import log as logging
|
17 | 17 | from haystack.utils.loading import UnifiedIndex
|
| 18 | +from haystack.utils.geo import Point |
18 | 19 |
|
19 | 20 | from ..core.models import (AFourthMockModel, AnotherMockModel, ASixthMockModel,
|
20 | 21 | MockModel)
|
@@ -436,6 +437,21 @@ def test_search(self):
|
436 | 437 | # Restore.
|
437 | 438 | settings.HAYSTACK_LIMIT_TO_REGISTERED_MODELS = old_limit_to_registered_models
|
438 | 439 |
|
| 440 | + def test_spatial_search_parameters(self): |
| 441 | + p1 = Point(1.23, 4.56) |
| 442 | + kwargs = self.sb.build_search_kwargs('*:*', distance_point={'field': 'location', 'point': p1}, |
| 443 | + sort_by=(('distance', 'desc'), )) |
| 444 | + |
| 445 | + self.assertIn('sort', kwargs) |
| 446 | + self.assertEqual(1, len(kwargs['sort'])) |
| 447 | + geo_d = kwargs['sort'][0]['_geo_distance'] |
| 448 | + |
| 449 | + # ElasticSearch supports the GeoJSON-style lng, lat pairs so unlike Solr the values should be |
| 450 | + # in the same order as we used to create the Point(): |
| 451 | + # http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-geo-distance-filter.html#_lat_lon_as_array_4 |
| 452 | + |
| 453 | + self.assertDictEqual(geo_d, {'location': [1.23, 4.56], 'unit': 'km', 'order': 'desc'}) |
| 454 | + |
439 | 455 | def test_more_like_this(self):
|
440 | 456 | self.sb.update(self.smmi, self.sample_objs)
|
441 | 457 | self.assertEqual(self.raw_search('*:*')['hits']['total'], 3)
|
|
0 commit comments