Class: SolrEad::Indexer
- Inherits:
-
Object
- Object
- SolrEad::Indexer
- Includes:
- RSolr, Behaviors
- Defined in:
- lib/solr_ead/indexer.rb
Overview
The main entry point for your ead going into solr.
SolrEad uses RSolr to connect to your solr server and then gives you a couple of simple methods for creating, updating and deleting your ead documents.
You’ll need to have your solr configuration defined in config/solr.yml. If you’re working within the Rails environment, it will obey your environment settings. However, if you are using the gem by itself outside of rails, you can use the RAILS_ENV environment variable, otherwise, it will default to the development url.
Default indexing
This will index your ead into one solr document for the main portion of ead and then multiple documents for the component documents. The fields for the main document are defined in SolrEad::Document and fields for the component are defined in SolrEad::Component.
> file = File.new("path/to/your/ead.xml")
> indexer = SolrEad::Indexer.new
> indexer.create(file)
> indexer.delete("EAD-ID")
Simple indexing
By using the :simple option, SolrEad will create only one solr document from one ead. The default implementation of SolrEad is to create multiple documents, so fields defined in SolrEad::Document reflect this. For example, no component fields are defined in SolrEad::Document, so none would be indexed. If you elect to use the :simple option, you’ll want to override SolrEad::Document with your own and define any additional component fields you want to appear in your index.
> file = File.new("path/to/your/ead.xml")
> indexer = SolrEad::Indexer.new(:simple => true)
> indexer.create(file)
> indexer.delete("EAD-ID")
Constant Summary
Constants included from Formatting
Instance Attribute Summary collapse
-
#options ⇒ Object
Returns the value of attribute options.
-
#solr ⇒ Object
Returns the value of attribute solr.
Instance Method Summary collapse
-
#create(file) ⇒ Object
Indexes ead xml and commits the results to your solr server.
-
#delete(id) ⇒ Object
Deletes the ead document and any component documents from your solr index and commits the results.
-
#initialize(opts = {}) ⇒ Indexer
constructor
Creates a new instance of SolrEad::Indexer and connects to your solr server.
-
#update(file) ⇒ Object
Updates your ead from a given file by first deleting the existing ead document and any component documents, then creating a new index from the supplied file.
Methods included from Behaviors
#additional_component_fields, #component_children?, #components, #get_title, #parent_id_list, #parent_unittitle_list, #prep
Methods included from Formatting
Constructor Details
#initialize(opts = {}) ⇒ Indexer
Creates a new instance of SolrEad::Indexer and connects to your solr server
42 43 44 45 |
# File 'lib/solr_ead/indexer.rb', line 42 def initialize opts={} self.solr = solr_connection self. = opts end |
Instance Attribute Details
#options ⇒ Object
Returns the value of attribute options.
39 40 41 |
# File 'lib/solr_ead/indexer.rb', line 39 def @options end |
#solr ⇒ Object
Returns the value of attribute solr.
39 40 41 |
# File 'lib/solr_ead/indexer.rb', line 39 def solr @solr end |
Instance Method Details
#create(file) ⇒ Object
Indexes ead xml and commits the results to your solr server.
48 49 50 51 52 |
# File 'lib/solr_ead/indexer.rb', line 48 def create file solr.add om_document(File.new(file)).to_solr add_components(file) unless [:simple] solr.commit end |
#delete(id) ⇒ Object
Deletes the ead document and any component documents from your solr index and commits the results.
67 68 69 70 |
# File 'lib/solr_ead/indexer.rb', line 67 def delete id solr.delete_by_query( Solrizer.solr_name("ead", :stored_sortable)+':"' + id + '"') solr.commit end |
#update(file) ⇒ Object
Updates your ead from a given file by first deleting the existing ead document and any component documents, then creating a new index from the supplied file. This method will also commit the results to your solr server when complete.
57 58 59 60 61 62 63 |
# File 'lib/solr_ead/indexer.rb', line 57 def update file solr_doc = om_document(File.new(file)).to_solr delete solr_doc["id"] solr.add solr_doc add_components(file) unless [:simple] solr.commit end |