From 326391037f4fdab93c1fee3090b4f02db1205839 Mon Sep 17 00:00:00 2001 From: david Date: Thu, 6 Oct 2016 13:20:19 +0200 Subject: [PATCH 1/2] Fixed highlight problem when a stemming dictionary is configured. --- lib/pg_search/features/tsearch.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/pg_search/features/tsearch.rb b/lib/pg_search/features/tsearch.rb index ebce1063..410a7f14 100644 --- a/lib/pg_search/features/tsearch.rb +++ b/lib/pg_search/features/tsearch.rb @@ -46,7 +46,7 @@ def checks_for_highlight end def ts_headline - "ts_headline((#{document}), (#{tsquery}), '#{ts_headline_options}')" + "ts_headline(#{dictionary.to_sql}, (#{document}), (#{tsquery}), '#{ts_headline_options}')" end def ts_headline_options From 1d77fbb60bbd171da488e4622a02651b179bf8db Mon Sep 17 00:00:00 2001 From: david Date: Fri, 23 Dec 2016 17:48:14 +0100 Subject: [PATCH 2/2] Added test of the highlight problem when a stemming dictionary is configured. --- spec/lib/pg_search/features/tsearch_spec.rb | 27 +++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/spec/lib/pg_search/features/tsearch_spec.rb b/spec/lib/pg_search/features/tsearch_spec.rb index 0948a930..3fc5cdde 100644 --- a/spec/lib/pg_search/features/tsearch_spec.rb +++ b/spec/lib/pg_search/features/tsearch_spec.rb @@ -122,4 +122,31 @@ end end end + + describe "#highlight" do + with_model :Model do + table do |t| + t.string :name + t.text :content + end + end + + context "when options[:dictionary] is passed" do + it 'uses the provided dictionary' do + query = "query" + columns = [ + PgSearch::Configuration::Column.new(:name, nil, Model), + PgSearch::Configuration::Column.new(:content, nil, Model), + ] + options = { dictionary: "spanish", highlight: {start_sel: "", stop_sel: ""} } + config = double(:config, :ignore => []) + normalizer = PgSearch::Normalizer.new(config) + + feature = described_class.new(query, options, columns, Model, normalizer) + expect(feature.highlight.to_sql).to eq( + %{(ts_headline('#{options[:dictionary]}', (coalesce(#{Model.quoted_table_name}."name"::text, '') || ' ' || coalesce(#{Model.quoted_table_name}."content"::text, '')), (to_tsquery('#{options[:dictionary]}', ''' ' || 'query' || ' ''')), 'StartSel = #{options[:highlight][:start_sel]}, StopSel = #{options[:highlight][:stop_sel]}'))} + ) + end + end + end end