Class: Hyrax::Statistics::TermQuery
- Inherits:
-
Object
- Object
- Hyrax::Statistics::TermQuery
- 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)
Direct Known Subclasses
FileSets::ByFormat, Works::ByDepositor, Works::ByResourceType
Defined Under Namespace
Classes: Result
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(limit = 5) ⇒ TermQuery
constructor
A new instance of TermQuery.
- #query ⇒ Object
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>
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
#query ⇒ Object
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 |