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 Sep 20, 2023
1 parent 2ed9190 commit c8b90a4
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 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
2 changes: 1 addition & 1 deletion lib/pg_search/features/tsearch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def highlight
def ts_headline
Arel::Nodes::NamedFunction.new("ts_headline", [
dictionary,
arel_wrap(document),
arel_wrap(document((options[:highlight] || {})[:separator])),
arel_wrap(tsquery),
Arel::Nodes.build_quoted(ts_headline_options)
]).to_sql
Expand Down

0 comments on commit c8b90a4

Please sign in to comment.