Skip to content

Commit

Permalink
tsearch: add configuration to customize columns separator
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
paulRbr committed May 16, 2022
1 parent d6064dc commit 9c43e48
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/pg_search/features/feature.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ def initialize(query, options, all_columns, model, normalizer)

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

def document
columns.map(&:to_sql).join(" || ' ' || ")
def document(separator = " ")
columns.map(&:to_sql).join(" || '#{separator}' || ")
end

def columns
Expand Down
1 change: 1 addition & 0 deletions lib/pg_search/features/tsearch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ def highlight
def ts_headline
Arel::Nodes::NamedFunction.new("ts_headline", [
dictionary,
arel_wrap(document((options[:highlight] || {})[:separator])),
arel_wrap(document),
arel_wrap(tsquery),
Arel::Nodes.build_quoted(ts_headline_options)
Expand Down

0 comments on commit 9c43e48

Please sign in to comment.