Commit 40bee0a05c8b5aef20a435a9c7b048ba3992f94e

Authored by will-r
1 parent 40049809

'contains' relation only available in ES 2.2+

README.md
... ... @@ -925,7 +925,7 @@ Any geospatial data type can be used in the index or in the search. It is up to
925 925  
926 926 See the [Elasticsearch documentation](https://www.elastic.co/guide/en/elasticsearch/reference/current/geo-shape.html) for details. GeoJSON coordinates are usually given as an array of `[lon, lat]` points but this often causes swapping errors so searchkick can also take objects with `lon` and `lat` keys.
927 927  
928   -Elasticsearch is sensitive about geo_shape validity. For example it will throw an exception if a polygon contains two consecutive identical points, or is not properly closed. You probably want to validate the data during indexing.
  928 +Elasticsearch is sensitive about geo_shape validity. For example it will throw an exception if a polygon contains two consecutive identical points, intersects itself or is not properly closed.
929 929  
930 930  
931 931 ### Geospatial searching
... ...
test/geo_shape_test.rb
... ... @@ -102,21 +102,19 @@ class GeoShapeTest < Minitest::Test
102 102 }
103 103 }, Region
104 104  
105   - # contains
106   - assert_search "*", ["Region A"], {
  105 + # with search
  106 + assert_search "witch", ["Region A"], {
107 107 where: {
108 108 territory: {
109 109 geo_shape: {
110 110 type: "envelope",
111   - relation: "contains",
112   - coordinates: [[32, 33], [33, 32]]
  111 + coordinates: [[28, 42], [32, 38]]
113 112 }
114 113 }
115 114 }
116 115 }, Region
117 116  
118   - # with search
119   - assert_search "witch", ["Region A"], {
  117 + assert_search "ginger hair", [], {
120 118 where: {
121 119 territory: {
122 120 geo_shape: {
... ... @@ -126,18 +124,22 @@ class GeoShapeTest < Minitest::Test
126 124 }
127 125 }
128 126 }, Region
  127 + end
129 128  
130   - assert_search "ginger hair", [], {
  129 + def test_geo_shape_contains
  130 + skip if elasticsearch_below22?
  131 +
  132 + assert_search "*", ["Region A"], {
131 133 where: {
132 134 territory: {
133 135 geo_shape: {
134 136 type: "envelope",
135   - coordinates: [[28, 42], [32, 38]]
  137 + relation: "contains",
  138 + coordinates: [[32, 33], [33, 32]]
136 139 }
137 140 }
138 141 }
139 142 }, Region
140 143  
141 144 end
142   -
143 145 end
... ...
test/test_helper.rb
... ... @@ -25,6 +25,10 @@ def elasticsearch_below50?
25 25 Searchkick.server_below?("5.0.0-alpha1")
26 26 end
27 27  
  28 +def elasticsearch_below22?
  29 + Searchkick.server_below?("2.2.0")
  30 +end
  31 +
28 32 def elasticsearch_below20?
29 33 Searchkick.server_below?("2.0.0")
30 34 end
... ...