Class: ActiveFedora::SolrService
- Inherits:
 - 
      Object
      
        
- Object
 - ActiveFedora::SolrService
 
 
- Defined in:
 - lib/active_fedora/solr_service.rb
 
Constant Summary collapse
- MAX_ROWS =
 10_000
Instance Attribute Summary collapse
- #conn ⇒ Object
 - 
  
    
      #options  ⇒ Object 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    
Returns the value of attribute options.
 
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
 - .post(query, args = {}) ⇒ 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.
      10 11 12  | 
    
      # File 'lib/active_fedora/solr_service.rb', line 10 def initialize( = {}) @options = { timeout: 120, open_timeout: 120, url: 'http://localhost:8080/solr' }.merge() end  | 
  
Instance Attribute Details
#conn ⇒ Object
      14 15 16  | 
    
      # File 'lib/active_fedora/solr_service.rb', line 14 def conn @conn ||= RSolr.connect @options end  | 
  
#options ⇒ Object (readonly)
Returns the value of attribute options.
      5 6 7  | 
    
      # File 'lib/active_fedora/solr_service.rb', line 5 def @options end  | 
  
Class Method Details
.add(doc, params = {}) ⇒ Object
      84 85 86  | 
    
      # File 'lib/active_fedora/solr_service.rb', line 84 def add(doc, params = {}) SolrService.instance.conn.add(doc, params: params) end  | 
  
.commit ⇒ Object
      88 89 90  | 
    
      # File 'lib/active_fedora/solr_service.rb', line 88 def commit SolrService.instance.conn.commit end  | 
  
.count(query, args = {}) ⇒ Integer
Get the count of records that match the query
      75 76 77 78  | 
    
      # File 'lib/active_fedora/solr_service.rb', line 75 def count(query, args = {}) args = args.merge(rows: 0) SolrService.get(query, args)['response']['numFound'].to_i end  | 
  
.delete(id) ⇒ Object
      67 68 69  | 
    
      # File 'lib/active_fedora/solr_service.rb', line 67 def delete(id) SolrService.instance.conn.delete_by_id(id, params: { 'softCommit' => true }) end  | 
  
.get(query, args = {}) ⇒ Object
      40 41 42 43  | 
    
      # File 'lib/active_fedora/solr_service.rb', line 40 def get(query, args = {}) args = args.merge(q: query, qt: 'standard') SolrService.instance.conn.get(select_path, params: args) end  | 
  
.instance ⇒ Object
      32 33 34 35 36 37 38  | 
    
      # File 'lib/active_fedora/solr_service.rb', line 32 def instance # Register Solr register(ActiveFedora.solr_config) unless ActiveFedora::RuntimeRegistry.solr_service ActiveFedora::RuntimeRegistry.solr_service end  | 
  
.post(query, args = {}) ⇒ Object
      45 46 47 48  | 
    
      # File 'lib/active_fedora/solr_service.rb', line 45 def post(query, args = {}) args = args.merge(q: query, qt: 'standard') SolrService.instance.conn.post(select_path, data: args) end  | 
  
.query(query, args = {}) ⇒ Object
      50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65  | 
    
      # File 'lib/active_fedora/solr_service.rb', line 50 def query(query, args = {}) Base.logger.warn "Calling ActiveFedora::SolrService.get without passing an explicit value for ':rows' is not recommended. You will end up with Solr's default (usually set to 10)\nCalled by #{caller[0]}" unless args.key?(:rows) method = args.delete(:method) || :get result = case method when :get get(query, args) when :post post(query, args) else raise "Unsupported HTTP method for querying SolrService (#{method.inspect})" end result['response']['docs'].map do |doc| ActiveFedora::SolrHit.new(doc) end end  | 
  
.register(options = {}) ⇒ Object
      20 21 22  | 
    
      # File 'lib/active_fedora/solr_service.rb', line 20 def register( = {}) ActiveFedora::RuntimeRegistry.solr_service = new() end  | 
  
.reset! ⇒ Object
      24 25 26  | 
    
      # File 'lib/active_fedora/solr_service.rb', line 24 def reset! ActiveFedora::RuntimeRegistry.solr_service = nil end  | 
  
.select_path ⇒ Object
      28 29 30  | 
    
      # File 'lib/active_fedora/solr_service.rb', line 28 def select_path ActiveFedora.solr_config.fetch(:select_path, 'select') end  |