Sha256: 0bb3230098b03b2ee2cebf020b4598197491ed42744a3acfe893787bf649942e

Contents?: true

Size: 1.47 KB

Versions: 9

Compression:

Stored size: 1.47 KB

Contents

module Geoblacklight
  module SpatialSearchBehavior
    extend ActiveSupport::Concern

    included do
      self.default_processor_chain += [:add_spatial_params]
    end

    ##
    # Adds spatial parameters to a Solr query if :bbox is present.
    # @param [Blacklight::Solr::Request] solr_params :bbox should be in Solr
    # :bbox should be passed in using Solr lat-lon rectangle format e.g.
    # "minX minY maxX maxY"
    # @return [Blacklight::Solr::Request]
    def add_spatial_params(solr_params)
      if blacklight_params[:bbox]
        solr_params[:bq] ||= []
        solr_params[:bq] << "#{Settings.FIELDS.GEOMETRY}:\"IsWithin(#{envelope_bounds})\"#{boost}"
        solr_params[:fq] ||= []
        solr_params[:fq] << "#{Settings.FIELDS.GEOMETRY}:\"Intersects(#{envelope_bounds})\""
      end
      solr_params
    rescue Geoblacklight::Exceptions::WrongBoundingBoxFormat
      # TODO: Potentially delete bbox params here so that its not rendered as search param
      solr_params
    end

    ##
    # @return [String]
    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]
    def bounding_box
      Geoblacklight::BoundingBox.from_rectangle(blacklight_params[:bbox])
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
geoblacklight-1.9.1 app/models/concerns/geoblacklight/spatial_search_behavior.rb
geoblacklight-1.9.0 app/models/concerns/geoblacklight/spatial_search_behavior.rb
geoblacklight-1.8.0 app/models/concerns/geoblacklight/spatial_search_behavior.rb
geoblacklight-1.7.1 app/models/concerns/geoblacklight/spatial_search_behavior.rb
geoblacklight-1.7.0 app/models/concerns/geoblacklight/spatial_search_behavior.rb
geoblacklight-1.6.0 app/models/concerns/geoblacklight/spatial_search_behavior.rb
geoblacklight-1.5.1 app/models/concerns/geoblacklight/spatial_search_behavior.rb
geoblacklight-1.5.0 app/models/concerns/geoblacklight/spatial_search_behavior.rb
geoblacklight-1.4.0 app/models/concerns/geoblacklight/spatial_search_behavior.rb