Sha256: 177e79015557008604b0c9ed2c1814ef619f1f608b5c8929c9d0429dfbd53f47

Contents?: true

Size: 1.34 KB

Versions: 4

Compression:

Stored size: 1.34 KB

Contents

class Hyrax::CatalogSearchBuilder < Hyrax::SearchBuilder
  self.default_processor_chain += [
    :add_access_controls_to_solr_params,
    :show_works_or_works_that_contain_files,
    :show_only_active_records
  ]

  # show both works that match the query and works that contain files that match the query
  def show_works_or_works_that_contain_files(solr_parameters)
    return if blacklight_params[:q].blank? || blacklight_params[:search_field]
    solr_parameters[:user_query] = blacklight_params[:q]
    solr_parameters[:q] = new_query
  end

  # show works that are in the active state.
  def show_only_active_records(solr_parameters)
    solr_parameters[:fq] ||= []
    solr_parameters[:fq] << '-suppressed_bsi:true'
  end

  private

    # the {!lucene} gives us the OR syntax
    def new_query
      "{!lucene}#{interal_query(dismax_query)} #{interal_query(join_for_works_from_files)}"
    end

    # the _query_ allows for another parser (aka dismax)
    def interal_query(query_value)
      "_query_:\"#{query_value}\""
    end

    # the {!dismax} causes the query to go against the query fields
    def dismax_query
      "{!dismax v=$user_query}"
    end

    # join from file id to work relationship solrized file_set_ids_ssim
    def join_for_works_from_files
      "{!join from=#{ActiveFedora.id_field} to=file_set_ids_ssim}#{dismax_query}"
    end
end

Version data entries

4 entries across 4 versions & 2 rubygems

Version Path
hyrax-1.0.1 app/search_builders/hyrax/catalog_search_builder.rb
hyrax-1.0.0.rc2 app/search_builders/hyrax/catalog_search_builder.rb
hyrax-1.0.0.rc1 app/search_builders/hyrax/catalog_search_builder.rb
test_hyrax-0.0.1.alpha app/search_builders/hyrax/catalog_search_builder.rb