Skip to content

Commit 1d77fbb

Browse files
committed
Added test of the highlight problem when a stemming dictionary is configured.
1 parent 3263910 commit 1d77fbb

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

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)