Class: Krikri::QASearchIndex
- Inherits:
-
SearchIndex
- Object
- SearchIndex
- Krikri::QASearchIndex
- Defined in:
- lib/krikri/search_index.rb
Overview
Generates flattened Solr documents and manages indexing of DPLA MAP models.
Instance Attribute Summary collapse
-
#solr ⇒ Object
readonly
Returns the value of attribute solr.
Instance Method Summary collapse
-
#add(doc) ⇒ Object
Adds a single JSON document to Solr.
-
#bulk_add(docs) ⇒ Object
Add multiple documents to Solr.
-
#commit ⇒ Object
Commits changes to Solr, making them visible to new requests Should be run after self.add and self.delete Okay to add or delete multiple docs and commit them all with a single self.commit.
-
#delete_by_id(id) ⇒ Object
Deletes an item from Solr.
-
#delete_by_query(query) ⇒ Object
Deletes items from Solr that match query.
-
#initialize(opts = {}) ⇒ QASearchIndex
constructor
A new instance of QASearchIndex.
-
#schema_keys ⇒ Array
Get field names from Solr schema in host application.
-
#solr_doc(doc) ⇒ Hash
Converts JSON document into a Hash that complies with Solr schema.
- #update_from_activity(activity) ⇒ Object
Constructor Details
#initialize(opts = {}) ⇒ QASearchIndex
Returns a new instance of QASearchIndex.
157 158 159 160 161 162 |
# File 'lib/krikri/search_index.rb', line 157 def initialize(opts = {}) # Override or append to default Solr options solr_opts = Krikri::Settings.solr.to_h.merge(opts) @solr = RSolr.connect(solr_opts) super(opts) end |
Instance Attribute Details
#solr ⇒ Object (readonly)
Returns the value of attribute solr.
152 153 154 |
# File 'lib/krikri/search_index.rb', line 152 def solr @solr end |
Instance Method Details
#add(doc) ⇒ Object
Adds a single JSON document to Solr
170 171 172 |
# File 'lib/krikri/search_index.rb', line 170 def add(doc) solr.add solr_doc(doc) end |
#bulk_add(docs) ⇒ Object
Add multiple documents to Solr
187 188 189 |
# File 'lib/krikri/search_index.rb', line 187 def bulk_add(docs) solr.add(docs.map { |d| solr_doc(d) }) end |
#commit ⇒ Object
Commits changes to Solr, making them visible to new requests Should be run after self.add and self.delete Okay to add or delete multiple docs and commit them all with a single self.commit
210 211 212 |
# File 'lib/krikri/search_index.rb', line 210 def commit solr.commit end |
#delete_by_id(id) ⇒ Object
Deletes an item from Solr
194 195 196 |
# File 'lib/krikri/search_index.rb', line 194 def delete_by_id(id) solr.delete_by_id id end |
#delete_by_query(query) ⇒ Object
Deletes items from Solr that match query
201 202 203 |
# File 'lib/krikri/search_index.rb', line 201 def delete_by_query(query) solr.delete_by_query query end |
#schema_keys ⇒ Array
Get field names from Solr schema in host application. Will raise exception if file not found.
226 227 228 229 230 231 232 |
# File 'lib/krikri/search_index.rb', line 226 def schema_keys schema_file = File.join(Rails.root, 'solr_conf', 'schema.xml') file = File.open(schema_file) doc = Nokogiri::XML(file) file.close doc.xpath('//fields/field').map { |f| f.attr('name') } end |
#solr_doc(doc) ⇒ Hash
Converts JSON document into a Hash that complies with Solr schema
218 219 220 |
# File 'lib/krikri/search_index.rb', line 218 def solr_doc(doc) remove_invalid_keys(flat_hash(doc)) end |