Skip to content

Commit c8b90a4

Browse files
committed
tsearch: add configuration to customize columns separator
When performing tsearch with Highlighting, the resulting query result concatenates the searched columns with a space. It can be hard to extract the different column data result if both data are text (containing spaces). In order to avoid this issue, we can allow users to customize the columns separator (which needs to be one of the word boundaries used by the query dictionnary). Partial solution for #336.
1 parent 2ed9190 commit c8b90a4

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

lib/pg_search/features/feature.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ def initialize(query, options, all_columns, model, normalizer)
2424

2525
attr_reader :query, :options, :all_columns, :model, :normalizer
2626

27-
def document
28-
columns.map(&:to_sql).join(" || ' ' || ")
27+
def document(separator = " ")
28+
columns.map(&:to_sql).join(" || '#{separator}' || ")
2929
end
3030

3131
def columns

lib/pg_search/features/tsearch.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def highlight
2929
def ts_headline
3030
Arel::Nodes::NamedFunction.new("ts_headline", [
3131
dictionary,
32-
arel_wrap(document),
32+
arel_wrap(document((options[:highlight] || {})[:separator])),
3333
arel_wrap(tsquery),
3434
Arel::Nodes.build_quoted(ts_headline_options)
3535
]).to_sql

0 commit comments

Comments
 (0)