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")
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 your ead and additional component documents with the supplied file, then 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 using the url supplied in your config/solr.yml file.
-
#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, #ead_clean_xml, #get_title, #parent_id_list, #parent_unittitle_list, #prep
Constructor Details
#initialize(opts = {}) ⇒ Indexer
Creates a new instance of SolrEad::Indexer and connects to your solr server using the url supplied in your config/solr.yml file.
43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/solr_ead/indexer.rb', line 43 def initialize(opts={}) Solrizer.default_field_mapper = EadMapper.new if defined?(Rails.root) url = YAML.load_file(File.join(Rails.root,"config","solr.yml"))[Rails.env]['url'] elsif ENV['RAILS_ENV'] url = YAML.load_file(File.join(Rails.root,"config","solr.yml"))[ENV['RAILS_ENV']]['url'] else url = YAML.load_file("config/solr.yml")['development']['url'] end self.solr = RSolr.connect :url => url 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 your ead and additional component documents with the supplied file, then commits the results to your solr server.
58 59 60 61 62 63 64 |
# File 'lib/solr_ead/indexer.rb', line 58 def create(file) doc = om_document(File.new(file)) solr_doc = doc.to_solr solr.add solr_doc 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.
80 81 82 83 |
# File 'lib/solr_ead/indexer.rb', line 80 def delete(id) solr.delete_by_query( 'ead_id:"' + 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.
69 70 71 72 73 74 75 76 |
# File 'lib/solr_ead/indexer.rb', line 69 def update(file) doc = om_document(File.new(file)) solr_doc = doc.to_solr solr.delete_by_query( 'ead_id:"' + solr_doc["id"] + '"' ) solr.add solr_doc add_components(file) unless [:simple] solr.commit end |