Sha256: 9d7bfae1c82f06417bd9d0ff65cc3690df48a847d54738473d00f867a1926ce1
Contents?: true
Size: 1.17 KB
Versions: 5
Compression:
Stored size: 1.17 KB
Contents
module SearchHelper def stub_nil_results connection.response = { 'response' => nil } end def stub_full_results(*results) count = if results.last.is_a?(Integer) then results.pop else results.length end docs = results.map do |result| instance = result.delete('instance') result.merge('id' => "#{instance.class.name} #{instance.id}") end response = { 'response' => { 'docs' => docs, 'numFound' => count } } connection.response = response response end def stub_results(*results) stub_full_results( *results.map do |result| if result.is_a?(Integer) result else { 'instance' => result } end end ) end def stub_stat(name, values) connection.response = { 'facet_counts' => { 'facet_fields' => { name.to_s => values.to_a.sort_by { |value, count| -count }.flatten } } } end def stat_field_name(result, field_name) result.stat(field_name).rows.map { |row| row.field_name } end def values(result, field_name) result.stat(field_name).rows.map { |row| row.value } end end
Version data entries
5 entries across 5 versions & 1 rubygems