Skip to content

Commit

Permalink
makes the bq boost value for bbox within matches configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
tampakis committed Nov 8, 2016
1 parent c6cf4dc commit df752da
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
8 changes: 7 additions & 1 deletion app/models/concerns/geoblacklight/spatial_search_behavior.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ module SpatialSearchBehavior
def add_spatial_params(solr_params)
if blacklight_params[:bbox]
solr_params[:bq] ||= []
solr_params[:bq] = ["#{Settings.FIELDS.GEOMETRY}:\"IsWithin(#{envelope_bounds})\"^10"]
solr_params[:bq] << "#{Settings.FIELDS.GEOMETRY}:\"IsWithin(#{envelope_bounds})\"#{boost}"
solr_params[:fq] ||= []
solr_params[:fq] << "#{Settings.FIELDS.GEOMETRY}:\"Intersects(#{envelope_bounds})\""
end
Expand All @@ -31,6 +31,12 @@ def envelope_bounds
bounding_box.to_envelope
end

## Allow bq boost to be configured, default 10 for backwards compatibility
# @return [String]
def boost
"^#{Settings.BBOX_WITHIN_BOOST || '10'}"
end

##
# Returns a Geoblacklight::BoundingBox built from the blacklight_params
# @return [Geoblacklight::BoundingBox]
Expand Down
5 changes: 4 additions & 1 deletion lib/generators/geoblacklight/templates/settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ CARTO_ONECLICK_LINK: 'http://oneclick.cartodb.com/'
# DEPRECATED Main Solr geometry field used for spatial search and bounding box. Should be type 'rpt'
GEOMETRY_FIELD: 'solr_geom'

#Solr field mappings
# The bq boost value for spatial search matches within a bounding box
BBOX_WITHIN_BOOST: '10'

# Solr field mappings
FIELDS:
:FILE_FORMAT: 'dc_format_s'
:GEOMETRY: 'solr_geom'
Expand Down
12 changes: 12 additions & 0 deletions spec/models/concerns/geoblacklight/spatial_search_behavior_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,18 @@
subject.with(params)
expect(subject.add_spatial_params(solr_params)[:fq].to_s).to include('Intersects')
end
it 'applies boost based on configured Settings.BBOX_WITHIN_BOOST' do
allow(Settings).to receive(:BBOX_WITHIN_BOOST).and_return 99
params = { bbox: '-180 -80 120 80' }
subject.with(params)
expect(subject.add_spatial_params(solr_params)[:bq].to_s).to include('^99')
end
it 'applies default boost of 10 when Settings.BBOX_WITHIN_BOOST not configured' do
allow(Settings).to receive(:BBOX_WITHIN_BOOST).and_return nil
params = { bbox: '-180 -80 120 80' }
subject.with(params)
expect(subject.add_spatial_params(solr_params)[:bq].to_s).to include('^10')
end
end
describe '#envelope_bounds' do
it 'calls to_envelope on the bounding box' do
Expand Down

0 comments on commit df752da

Please sign in to comment.