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.
161 162 163 164 165 166 |
# File 'lib/krikri/search_index.rb', line 161 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.
156 157 158 |
# File 'lib/krikri/search_index.rb', line 156 def solr @solr end |
Instance Method Details
#add(doc) ⇒ Object
Adds a single JSON document to Solr
174 175 176 |
# File 'lib/krikri/search_index.rb', line 174 def add(doc) solr.add solr_doc(doc) end |
#bulk_add(docs) ⇒ Object
Add multiple documents to Solr
191 192 193 |
# File 'lib/krikri/search_index.rb', line 191 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
214 215 216 |
# File 'lib/krikri/search_index.rb', line 214 def commit solr.commit end |
#delete_by_id(id) ⇒ Object
Deletes an item from Solr
198 199 200 |
# File 'lib/krikri/search_index.rb', line 198 def delete_by_id(id) solr.delete_by_id id end |
#delete_by_query(query) ⇒ Object
Deletes items from Solr that match query
205 206 207 |
# File 'lib/krikri/search_index.rb', line 205 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.
230 231 232 233 234 235 236 |
# File 'lib/krikri/search_index.rb', line 230 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
222 223 224 |
# File 'lib/krikri/search_index.rb', line 222 def solr_doc(doc) remove_invalid_keys(flat_hash(doc)) end |