module Birds::App::Helpers::Controller

Public Instance Methods

explain_result(result = @result) click to toggle source
    # File lib/birds/app/helpers/controller.rb
104 def explain_result(result = @result)
105   result.debug_explain if result && result.debug?
106 end
facet_counts(result = @result) click to toggle source
    # File lib/birds/app/helpers/controller.rb
108 def facet_counts(result = @result)
109   return {} unless result && result.to_i > 1 && result.facet_counts?
110 
111   exclude, prepare = [@query, *@filter], lambda { |facet_hash, &block|
112     facet_hash.delete_if { |key, hash|
113       gap = block[hash] if block
114 
115       hash.delete_if { |term,|
116         exclude.include?(facet_query(key, term, *gap)) }.size < 2
117     }
118   }
119 
120   prepare.(result.facet_fields.to_h).merge(
121   prepare.(result.facet_ranges.to_h) { |hash|
122     counts, before, start, gap = hash
123       .values_at(*%w[counts before start gap])
124 
125     hash.clear
126     hash[-start] = before if before && before > 1
127     counts.each { |value, count| hash[value.to_i] = count }
128 
129     hash.singleton_class.send(:define_method, :gap) { gap }
130     gap
131   })
132 end
facet_params(params = {}) click to toggle source
   # File lib/birds/app/helpers/controller.rb
72 def facet_params(params = {})
73   params.merge(f: f = params[:f] || {}, facet: {
74     field: fields = [], range: ranges = [], mincount: 1
75   }).tap { settings.facet_fields.each { |facet, (_, options)|
76     options.nil? ? fields << facet : begin ranges << facet
77       ((f[facet] ||= {})[:facet] ||= {})[:range] = options
78     end
79   } }
80 end
highlighting(result = @result) click to toggle source
    # File lib/birds/app/helpers/controller.rb
134 def highlighting(result = @result)
135   result.highlighting if result && result.highlighting?
136 end
highlighting_params(params = {}) click to toggle source
   # File lib/birds/app/helpers/controller.rb
82 def highlighting_params(params = {})
83   params.merge(hl: {
84     fl:              settings.highlighting_fields,
85     snippets:        settings.highlighting_snippets,
86     fragsize:        settings.highlighting_fragsize,
87     mergeContiguous: true,
88     preserveMulti:   true,
89     simple: {
90       pre:  settings.highlighting_prefix,
91       post: settings.highlighting_postfix
92     }
93   })
94 end
paginate_query(query, what, query_params = {}) click to toggle source
   # File lib/birds/app/helpers/controller.rb
54 def paginate_query(query, what, query_params = {})
55   return unless query
56 
57   page, per_page = clip(params[:page].to_i),
58     clip(Integer(params[:per_page] || settings.default_per_page))
59 
60   @prev_page, @next_page = page - 1, page + 1
61 
62   @result = search_query(query, query_params.merge(
63     rows: per_page, start: @offset = @prev_page * per_page))
64 
65   @page_title_extra = '%d %s, page %d of %d' % [@result, what,
66     page, @total_pages = clip(@result.to_i.fdiv(per_page).ceil)]
67 
68   @prev_page = nil if @prev_page < 1
69   @next_page = nil if @next_page > @total_pages
70 end
search_document(id) click to toggle source
   # File lib/birds/app/helpers/controller.rb
50 def search_document(id)
51   search(q: { id: id }).first
52 end
search_query(query, params = {}) click to toggle source
   # File lib/birds/app/helpers/controller.rb
46 def search_query(query, params = {})
47   search(params.merge(q: query, fl: '*,score', defType: 'edismax'))
48 end
solr_query(path, params = {}, options = {}, &block) click to toggle source
   # File lib/birds/app/helpers/controller.rb
34 def solr_query(path, params = {}, options = {}, &block)
35   settings.solr.json_query(params, options, path, &block)
36 end
spell_query(query, params = {}) click to toggle source
   # File lib/birds/app/helpers/controller.rb
42 def spell_query(query, params = {})
43   solr_query(settings.solr_spell_path, params.merge(q: query))
44 end
spellcheck_collations(result = @result, limit = nil) click to toggle source
    # File lib/birds/app/helpers/controller.rb
138 def spellcheck_collations(result = @result, limit = nil)
139   result.spellcheck_collations(limit) if result && result.spellcheck?
140 end
spellcheck_params(params = {}) click to toggle source
   # File lib/birds/app/helpers/controller.rb
96 def spellcheck_params(params = {})
97   params.merge(spellcheck: { collate: true })
98 end
terms(f = @field) click to toggle source
    # File lib/birds/app/helpers/controller.rb
100 def terms(f = @field)
101   settings.solr.json('terms', terms: { fl: f, limit: -1 }).to_h[f].sort
102 end

Private Instance Methods

clip(num, min = 1) click to toggle source
    # File lib/birds/app/helpers/controller.rb
144 def clip(num, min = 1)
145   num < min ? min : num
146 end