Class: Hyrax::Statistics::TermQuery

Inherits:
Object
  • Object
show all
Defined in:
app/services/hyrax/statistics/term_query.rb

Overview

An abstract class for running a query against the Solr terms component you must implement ‘index_key` in the concrete class.

WARNING: you must use a term that isn’t parsed (i.e. use _sim instead of _tesim)

Defined Under Namespace

Classes: Result

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(limit = 5) ⇒ TermQuery

Returns a new instance of TermQuery.



15
16
17
# File 'app/services/hyrax/statistics/term_query.rb', line 15

def initialize(limit = 5)
  @limit = limit
end

Class Method Details

.query(limit: 5) ⇒ Array<Hyrax::Statistics::TermQuery::Result>

Parameters:

  • limit (Integer) (defaults to: 5)
    • Limit the number of responses

Returns:



11
12
13
# File 'app/services/hyrax/statistics/term_query.rb', line 11

def self.query(limit: 5)
  new(limit).query
end

Instance Method Details

#queryObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'app/services/hyrax/statistics/term_query.rb', line 19

def query
  term = index_key
  # Grab JSON response (looks like {"terms": {"depositor_tesim": {"mjg36": 3}}} for depositor)
  json = solr_connection.get 'terms', params: { 'terms.fl' => term,
                                                'terms.sort' => 'count',
                                                'terms.limit' => @limit,
                                                wt: 'json',
                                                'json.nl' => 'map',
                                                omitHeader: 'true' }
  unless json
    Rails.logger.error "Unable to reach TermsComponent via Solr connection. Is it enabled in your solr config?"
    return []
  end

  Result.build(json['terms'][term])
end