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

Instance Method Summary collapse

Constructor Details

#initialize(limit = 5) ⇒ TermQuery

Returns a new instance of TermQuery.



8
9
10
# File 'app/services/hyrax/statistics/term_query.rb', line 8

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

Instance Method Details

#queryObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'app/services/hyrax/statistics/term_query.rb', line 12

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