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.


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

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:


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

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

Instance Method Details

#queryObject


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

def query
  term = index_key
  # Grab JSON response (looks like {"terms": {"depositor_tesim": {"mjg36": 3}}} for depositor)
  json = Hyrax::SolrService.get(path: 'terms',
                                '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