Class: Blacklight::Solr::Repository
- Inherits:
-
AbstractRepository
- Object
- AbstractRepository
- Blacklight::Solr::Repository
- Defined in:
- lib/blacklight/solr/repository.rb
Instance Attribute Summary
Attributes inherited from AbstractRepository
#blacklight_config, #connection
Instance Method Summary collapse
- #build_connection ⇒ Object protected
-
#find(id, params = {}) ⇒ Object
Find a single solr document result (by id) using the document configuration.
-
#ping ⇒ boolean
True if the repository is reachable.
-
#reflect_fields ⇒ Hash
Gets a list of available fields.
-
#search(params = {}) ⇒ Object
Execute a search query against solr.
-
#send_and_receive(path, solr_params = {}) ⇒ Blacklight::Solr::Response
Execute a solr query TODO: Make this private after we have a way to abstract admin/luke and ping.
- #suggest_handler_path ⇒ String protected
- #suggester_name ⇒ Object protected
- #suggestions(request_params) ⇒ Blacklight::Suggest::Response
Methods inherited from AbstractRepository
Constructor Details
This class inherits a constructor from Blacklight::AbstractRepository
Instance Method Details
#build_connection ⇒ Object (protected)
87 88 89 |
# File 'lib/blacklight/solr/repository.rb', line 87 def build_connection RSolr.connect(connection_config.merge(adapter: connection_config[:http_adapter])) end |
#find(id, params = {}) ⇒ Object
Find a single solr document result (by id) using the document configuration
8 9 10 11 12 13 14 15 16 |
# File 'lib/blacklight/solr/repository.rb', line 8 def find id, params = {} doc_params = params.reverse_merge(blacklight_config.default_document_solr_params) .reverse_merge(qt: blacklight_config.document_solr_request_handler) .merge(blacklight_config.document_unique_id_param => id) solr_response = send_and_receive blacklight_config.document_solr_path || blacklight_config.solr_path, doc_params raise Blacklight::Exceptions::RecordNotFound if solr_response.documents.empty? solr_response end |
#ping ⇒ boolean
Returns true if the repository is reachable.
41 42 43 44 45 |
# File 'lib/blacklight/solr/repository.rb', line 41 def ping response = connection.send_and_receive 'admin/ping', {} Blacklight.logger.info("Ping [#{connection.uri}] returned: '#{response['status']}'") response['status'] == "OK" end |
#reflect_fields ⇒ Hash
Gets a list of available fields
35 36 37 |
# File 'lib/blacklight/solr/repository.rb', line 35 def reflect_fields send_and_receive('admin/luke', params: { fl: '*', 'json.nl' => 'map' })['fields'] end |
#search(params = {}) ⇒ Object
Execute a search query against solr
21 22 23 |
# File 'lib/blacklight/solr/repository.rb', line 21 def search params = {} send_and_receive blacklight_config.solr_path, params.reverse_merge(qt: blacklight_config.qt) end |
#find(solr_path, params) ⇒ Blacklight::Solr::Response #find(params) ⇒ Blacklight::Solr::Response
Execute a solr query TODO: Make this private after we have a way to abstract admin/luke and ping
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/blacklight/solr/repository.rb', line 58 def send_and_receive(path, solr_params = {}) benchmark("Solr fetch", level: :debug) do key = blacklight_config.http_method == :post ? :data : :params res = connection.send_and_receive(path, {key=>solr_params.to_hash, method: blacklight_config.http_method}) solr_response = blacklight_config.response_model.new(res, solr_params, document_model: blacklight_config.document_model, blacklight_config: blacklight_config) Blacklight.logger.debug("Solr query: #{blacklight_config.http_method} #{path} #{solr_params.to_hash.inspect}") Blacklight.logger.debug("Solr response: #{solr_response.inspect}") if defined?(::BLACKLIGHT_VERBOSE_LOGGING) and ::BLACKLIGHT_VERBOSE_LOGGING solr_response end rescue Errno::ECONNREFUSED => e raise Blacklight::Exceptions::ECONNREFUSED, "Unable to connect to Solr instance using #{connection.inspect}: #{e.inspect}" rescue RSolr::Error::Http => e raise Blacklight::Exceptions::InvalidRequest, e. end |
#suggest_handler_path ⇒ String (protected)
79 80 81 |
# File 'lib/blacklight/solr/repository.rb', line 79 def suggest_handler_path blacklight_config.autocomplete_path end |
#suggester_name ⇒ Object (protected)
83 84 85 |
# File 'lib/blacklight/solr/repository.rb', line 83 def suggester_name blacklight_config.autocomplete_suggester end |
#suggestions(request_params) ⇒ Blacklight::Suggest::Response
27 28 29 30 |
# File 'lib/blacklight/solr/repository.rb', line 27 def suggestions(request_params) suggest_results = connection.send_and_receive(suggest_handler_path, params: request_params) Blacklight::Suggest::Response.new suggest_results, request_params, suggest_handler_path, suggester_name end |