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.
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>
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
#query ⇒ Object
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 Hyrax.logger.error "Unable to reach TermsComponent via Solr connection. Is it enabled in your solr config?" return [] end Result.build(json['terms'][term]) end |