Skip to content
This repository has been archived by the owner on Dec 1, 2021. It is now read-only.

Date and range support #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions lib/delsolr/query_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -189,16 +189,27 @@ def build_facet(facet_hash)
facet_hash[:localparams][:key] ||= facet_name
end
facet_local_params = build_local_params(facet_hash['localparams'] || facet_hash[:localparams])

field_name = nil

if facet_hash[:field]
field_name = facet_hash[:field]
elsif facet_hash[:range]
field_name = facet_hash[:range]
elsif facet_hash[:date]
field_name = facet_hash[:date]
end

facet_hash.each do |k,v|
# handle some cases specially
if 'field' == k.to_s
params << {"facet.field" => "#{facet_local_params}#{v}"}
if ['field', 'range', 'date'].include? k.to_s
params << {"facet.#{k}" => "#{facet_local_params}#{v}"}
elsif 'query' == k.to_s
params << build_query("facet.query", v, facet_local_params)
elsif ['localparams', :localparams, 'name', :name].include?(k.to_s)
# do nothing
else
params << {"f.#{facet_hash[:field]}.facet.#{k}" => "#{v}"}
params << {"f.#{field_name}.facet.#{k}" => "#{v}"}
end
end
params
Expand Down
10 changes: 8 additions & 2 deletions lib/delsolr/response.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ class Client
class Response

attr_reader :query_builder
attr_accessor :docs, :facet_dates, :facet_fields_by_hash # We're merging results into this array - so need to be able to set it.

def initialize(solr_response_buffer, query_builder, options = {})
@query_builder = query_builder
Expand Down Expand Up @@ -70,7 +71,7 @@ def max_score
def docs
@docs ||= raw_response['response']['docs']
end

# Helper for displaying a given field (first tries the highlight, then the stored value)
def display_for(doc, field)
highlights_for(doc['unique_id'], field) || doc[field]
Expand Down Expand Up @@ -127,7 +128,12 @@ def facet_fields
def facet_queries
@facet_queries ||= facets['facet_queries'] || {}
end


# Returns all facet dates
def facet_dates
@facet_dates ||= facets['facet_dates'] || {}
end

# Returns a hash of hashs rather than a hash of arrays (ie: {'instock_b' => {'true' => 123', 'false', => 20} })
def facet_fields_by_hash
@facet_fields_by_hash ||= begin
Expand Down