Last active
August 29, 2015 14:02
-
-
Save jlecour/a99a4f42edadf5d801e5 to your computer and use it in GitHub Desktop.
Revisions
-
jlecour revised this gist
Jun 16, 2014 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,6 @@ def distance_script_field(name: "distance", field: "lat_lng", lat:, lng:) valid_pattern = /\A[\w]+\Z/ valid_pattern.match(name) or fail(ArgumentError, "Invalid value for name: #{name.inspect}") valid_pattern.match(field) or fail(ArgumentError, "Invalid value for field: #{field.inspect}") Float(lat) rescue raise(ArgumentError, "Invalid value for lat: #{lat.inspect}") Float(lng) rescue raise(ArgumentError, "Invalid value for lng: #{lng.inspect}") -
jlecour created this gist
Jun 16, 2014 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,17 @@ def distance_script_field(name: "distance", field: "lat_lng", lat:, lng:) valid_pattern = /\A[\w]+\Z/ valid_pattern.match(name) or fail(ArgumentError, "Invalid value for name: #{field.inspect}") valid_pattern.match(field) or fail(ArgumentError, "Invalid value for field: #{field.inspect}") Float(lat) rescue raise(ArgumentError, "Invalid value for lat: #{lat.inspect}") Float(lng) rescue raise(ArgumentError, "Invalid value for lng: #{lng.inspect}") { name => { script: "doc['#{field}'].arcDistanceInKm(lat,lon)", params: { lat: lat, lon: lng } } } end This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,11 @@ def distance_script_field(name: "distance", field: "lat_lng", lat:, lng:) { name => { script: "doc['#{field}'].arcDistanceInKm(lat,lon)", params: { lat: lat, lon: lng } } } end