Skip to content

Commit 07426a8

Browse files
authored
Merge pull request #331 from nlpgo/master
Fixed highlight problem when a stemming dictionary is configured.
2 parents 1168b3b + 1d77fbb commit 07426a8

2 files changed

Lines changed: 28 additions & 1 deletion

File tree

lib/pg_search/features/tsearch.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def highlight
2424
private
2525

2626
def ts_headline
27-
"ts_headline((#{document}), (#{tsquery}), '#{ts_headline_options}')"
27+
"ts_headline(#{dictionary.to_sql}, (#{document}), (#{tsquery}), '#{ts_headline_options}')"
2828
end
2929

3030
def ts_headline_options

spec/lib/pg_search/features/tsearch_spec.rb

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,4 +122,31 @@
122122
end
123123
end
124124
end
125+
126+
describe "#highlight" do
127+
with_model :Model do
128+
table do |t|
129+
t.string :name
130+
t.text :content
131+
end
132+
end
133+
134+
context "when options[:dictionary] is passed" do
135+
it 'uses the provided dictionary' do
136+
query = "query"
137+
columns = [
138+
PgSearch::Configuration::Column.new(:name, nil, Model),
139+
PgSearch::Configuration::Column.new(:content, nil, Model),
140+
]
141+
options = { dictionary: "spanish", highlight: {start_sel: "<b>", stop_sel: "</b>"} }
142+
config = double(:config, :ignore => [])
143+
normalizer = PgSearch::Normalizer.new(config)
144+
145+
feature = described_class.new(query, options, columns, Model, normalizer)
146+
expect(feature.highlight.to_sql).to eq(
147+
%{(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]}'))}
148+
)
149+
end
150+
end
151+
end
125152
end

0 commit comments

Comments
 (0)