Module: Geoblacklight::SpatialSearchBehavior

Extended by:
ActiveSupport::Concern
Defined in:
app/models/concerns/geoblacklight/spatial_search_behavior.rb

Instance Method Summary collapse

Instance Method Details

#add_spatial_params(solr_params) ⇒ Blacklight::Solr::Request

Adds spatial parameters to a Solr query if :bbox is present. :bbox should be passed in using Solr lat-lon rectangle format e.g. “minX minY maxX maxY”

Parameters:

  • solr_params (Blacklight::Solr::Request)

    :bbox should be in Solr

Returns:

  • (Blacklight::Solr::Request)


16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'app/models/concerns/geoblacklight/spatial_search_behavior.rb', line 16

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})\""

    if Settings.OVERLAP_RATIO_BOOST
      solr_params[:bf] ||= []
      solr_params[:overlap] =
        "{!field uf=* defType=lucene f=#{Settings.FIELDS.OVERLAP_FIELD} score=overlapRatio}Intersects(#{envelope_bounds})"
      solr_params[:bf] << "$overlap^#{Settings.OVERLAP_RATIO_BOOST}"
    end
  end
  solr_params
rescue Geoblacklight::Exceptions::WrongBoundingBoxFormat
  # TODO: Potentially delete bbox params here so that its not rendered as search param
  solr_params
end

#boostString

Allow bq boost to be configured, default 10 for backwards compatibility

Returns:

  • (String)


44
45
46
# File 'app/models/concerns/geoblacklight/spatial_search_behavior.rb', line 44

def boost
  "^#{Settings.BBOX_WITHIN_BOOST || '10'}"
end

#bounding_boxGeoblacklight::BoundingBox

Returns a Geoblacklight::BoundingBox built from the blacklight_params



51
52
53
# File 'app/models/concerns/geoblacklight/spatial_search_behavior.rb', line 51

def bounding_box
  Geoblacklight::BoundingBox.from_rectangle(blacklight_params[:bbox])
end

#envelope_boundsString

Returns:

  • (String)


38
39
40
# File 'app/models/concerns/geoblacklight/spatial_search_behavior.rb', line 38

def envelope_bounds
  bounding_box.to_envelope
end

#hide_suppressed_records(solr_params) ⇒ Blacklight::Solr::Request

Hide suppressed records in search

Parameters:

  • (Blacklight::Solr::Request)

Returns:

  • (Blacklight::Solr::Request)


59
60
61
62
63
64
65
66
67
68
69
# File 'app/models/concerns/geoblacklight/spatial_search_behavior.rb', line 59

def hide_suppressed_records(solr_params)
  # Show child records if searching for a specific source parent
  return unless blacklight_params.fetch(:f, {})[Settings.FIELDS.SOURCE.to_sym].nil?

  # Do not suppress action_documents method calls for individual documents
  # ex. CatalogController#web_services (exportable views)
  return if solr_params[:q]&.include?("{!lucene}#{Settings.FIELDS.UNIQUE_KEY}:")

  solr_params[:fq] ||= []
  solr_params[:fq] << "-#{Settings.FIELDS.SUPPRESSED}: true"
end