Skip to content
Merged
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
4 changes: 2 additions & 2 deletions sunspot/lib/sunspot/query/abstract_json_field_facet.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require 'json' # to_params serializes the facet with to_json
require 'json'

module Sunspot
module Query
Expand Down Expand Up @@ -49,7 +49,7 @@ def get_params
end

def to_params
{ 'json.facet' => self.get_params.to_json }
{ 'json.facet' => JSON.generate(get_params) }
end

private
Expand Down
2 changes: 1 addition & 1 deletion sunspot/lib/sunspot/query/field_stats.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def add_json_facet(json_facet)
def to_params
params = {}
if !@json_facet.nil?
params['json.facet'] = recursive_add_stats(@json_facet.get_params).to_json
params['json.facet'] = JSON.generate(recursive_add_stats(@json_facet.get_params))
else
params.merge!(:stats => true, :"stats.field" => [@field.indexed_name])
params[facet_key] = @facets.map(&:indexed_name) unless @facets.empty?
Expand Down
7 changes: 7 additions & 0 deletions sunspot/spec/api/nested_documents_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,13 @@ def json_facet
})
end

it "serializes its params with JSON.generate, not Hash#to_json, which ActiveSupport 6.1 breaks under json 3" do
allow_any_instance_of(Hash).to receive(:to_json).and_raise(ArgumentError, 'unknown keyword: quirks_mode')

session.search(Project) { child_facet(:milestones, :name) }
expect(json_facet.keys).to eq(['name'])
end

it 'is keyed by its :name' do
session.search(Project) { child_facet(:milestones, :name, :name => :milestone_name) }
expect(json_facet.keys).to eq(['milestone_name'])
Expand Down
Loading