Skip to content

Commit 9c43e48

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 d6064dc commit 9c43e48

2 files changed

Lines changed: 3 additions & 2 deletions

File tree

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 & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ def highlight
2929
def ts_headline
3030
Arel::Nodes::NamedFunction.new("ts_headline", [
3131
dictionary,
32+
arel_wrap(document((options[:highlight] || {})[:separator])),
3233
arel_wrap(document),
3334
arel_wrap(tsquery),
3435
Arel::Nodes.build_quoted(ts_headline_options)

0 commit comments

Comments
 (0)