Class: ActiveFedora::SolrService
- Inherits:
-
Object
- Object
- ActiveFedora::SolrService
- Defined in:
- lib/active_fedora/solr_service.rb
Instance Attribute Summary collapse
Class Method Summary collapse
- .add(doc, params = {}) ⇒ Object
- .commit ⇒ Object
-
.count(query, args = {}) ⇒ Integer
Get the count of records that match the query.
- .delete(id) ⇒ Object
- .get(query, args = {}) ⇒ Object
- .instance ⇒ Object
- .query(query, args = {}) ⇒ Object
- .register(options = {}) ⇒ Object
- .reset! ⇒ Object
- .select_path ⇒ Object
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ SolrService
constructor
A new instance of SolrService.
Constructor Details
#initialize(options = {}) ⇒ SolrService
Returns a new instance of SolrService.
7 8 9 |
# File 'lib/active_fedora/solr_service.rb', line 7 def initialize( = {}) @options = { read_timeout: 120, open_timeout: 120, url: 'http://localhost:8080/solr' }.merge() end |
Instance Attribute Details
#conn ⇒ Object
11 12 13 |
# File 'lib/active_fedora/solr_service.rb', line 11 def conn @conn ||= RSolr.connect @options end |
Class Method Details
.add(doc, params = {}) ⇒ Object
68 69 70 |
# File 'lib/active_fedora/solr_service.rb', line 68 def add(doc, params = {}) SolrService.instance.conn.add(doc, params: params) end |
.commit ⇒ Object
72 73 74 |
# File 'lib/active_fedora/solr_service.rb', line 72 def commit SolrService.instance.conn.commit end |
.count(query, args = {}) ⇒ Integer
Get the count of records that match the query
59 60 61 62 |
# File 'lib/active_fedora/solr_service.rb', line 59 def count(query, args = {}) args = args.merge(rows: 0) SolrService.get(query, args)['response']['numFound'].to_i end |
.delete(id) ⇒ Object
51 52 53 |
# File 'lib/active_fedora/solr_service.rb', line 51 def delete(id) SolrService.instance.conn.delete_by_id(id, params: { 'softCommit' => true }) end |
.get(query, args = {}) ⇒ Object
39 40 41 42 |
# File 'lib/active_fedora/solr_service.rb', line 39 def get(query, args = {}) args = args.merge(q: query, qt: 'standard') SolrService.instance.conn.get(select_path, params: args) end |
.instance ⇒ Object
29 30 31 32 33 34 35 36 37 |
# File 'lib/active_fedora/solr_service.rb', line 29 def instance # Register Solr unless ActiveFedora::RuntimeRegistry.solr_service register(ActiveFedora.solr_config) end ActiveFedora::RuntimeRegistry.solr_service end |
.query(query, args = {}) ⇒ Object
44 45 46 47 48 49 |
# File 'lib/active_fedora/solr_service.rb', line 44 def query(query, args = {}) result = get(query, args) result['response']['docs'].map do |doc| ActiveFedora::SolrHit.new(doc) end end |
.register(options = {}) ⇒ Object
17 18 19 |
# File 'lib/active_fedora/solr_service.rb', line 17 def register( = {}) ActiveFedora::RuntimeRegistry.solr_service = new() end |
.reset! ⇒ Object
21 22 23 |
# File 'lib/active_fedora/solr_service.rb', line 21 def reset! ActiveFedora::RuntimeRegistry.solr_service = nil end |
.select_path ⇒ Object
25 26 27 |
# File 'lib/active_fedora/solr_service.rb', line 25 def select_path ActiveFedora.solr_config.fetch(:select_path, 'select') end |