-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Filtering by geo arbitrary rectangle (#64)
- Loading branch information
Showing
14 changed files
with
131 additions
and
35 deletions.
There are no files selected for viewing
This file contains 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 characters
This file contains 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 characters
This file contains 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 characters
This file contains 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 characters
This file contains 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 characters
This file was deleted.
Oops, something went wrong.
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
module Solr | ||
module Query | ||
class Request | ||
class Geofilt | ||
include Solr::Support::SchemaHelper | ||
|
||
attr_reader :field, :spatial_point, :spatial_radius, :score | ||
|
||
def initialize(field:, spatial_point:, spatial_radius:, score: nil) | ||
raise ArgumentError, 'spatial_point must be a Solr::SpatialPoint' unless spatial_point.is_a?(Solr::SpatialPoint) | ||
|
||
@field = field | ||
@spatial_point = spatial_point | ||
@spatial_radius = spatial_radius | ||
@score = score | ||
freeze | ||
end | ||
|
||
def to_solr_s | ||
solr_field = solarize_field(@field) | ||
filter = "{!geofilt sfield=#{solr_field} pt=#{spatial_point.to_solr_s} d=#{spatial_radius}" | ||
filter << " score=#{score}" if score | ||
filter + "}" | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
module Solr | ||
class SpatialPoint | ||
attr_reader :lat, :lon | ||
|
||
def initialize(lat:, lon:) | ||
@lat = lat | ||
@lon = lon | ||
end | ||
|
||
def to_solr_s | ||
"#{lat},#{lon}" | ||
end | ||
end | ||
end |
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
module Solr | ||
class SpatialRectangle | ||
attr_reader :top_right, :bottom_left | ||
|
||
def initialize(top_right:, bottom_left:) | ||
raise ArgumentError, 'top_right must be a Solr::SpatialPoint' unless top_right.is_a?(Solr::SpatialPoint) | ||
raise ArgumentError, 'bottom_left must be a Solr::SpatialPoint' unless bottom_left.is_a?(Solr::SpatialPoint) | ||
|
||
@top_right = top_right | ||
@bottom_left = bottom_left | ||
end | ||
|
||
def to_solr_s | ||
"[#{bottom_left.to_solr_s} TO #{top_right.to_solr_s}]" | ||
end | ||
end | ||
end |
This file contains 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 characters
This file was deleted.
Oops, something went wrong.
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
RSpec.describe Solr::Query::Request::Geofilt do | ||
describe '.to_solr_s' do | ||
let(:spatial_point) { Solr::SpatialPoint.new(lat: -25.429692, lon: -49.271265) } | ||
|
||
subject { described_class.new(field: :machine_type, spatial_point: spatial_point, spatial_radius: 161) } | ||
|
||
it { expect(subject.to_solr_s).to eq('{!geofilt sfield=machine_type pt=-25.429692,-49.271265 d=161}') } | ||
end | ||
end |
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
RSpec.describe Solr::SpatialPoint do | ||
describe '#to_solr_s' do | ||
it 'returns a solr string' do | ||
expect(described_class.new(lat: 1.0, lon: 2.0).to_solr_s).to eq('1.0,2.0') | ||
end | ||
end | ||
end |
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
RSpec.describe Solr::SpatialRectangle do | ||
describe '#to_solr_s' do | ||
it 'returns a solr string' do | ||
expect(described_class.new( | ||
top_right: Solr::SpatialPoint.new(lat: 1.0, lon: 2.0), | ||
bottom_left: Solr::SpatialPoint.new(lat: 3.0, lon: 4.0) | ||
).to_solr_s).to eq('[3.0,4.0 TO 1.0,2.0]') | ||
end | ||
end | ||
end |