Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed highlight problem when a stemming dictionary is configured. #331

Merged
merged 2 commits into from
Jan 16, 2017
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
2 changes: 1 addition & 1 deletion lib/pg_search/features/tsearch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
27 changes: 27 additions & 0 deletions spec/lib/pg_search/features/tsearch_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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: "<b>", stop_sel: "</b>"} }
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