Class: PgSearch::Normalizer
- Inherits:
-
Object
- Object
- PgSearch::Normalizer
- Defined in:
- lib/pg_search/normalizer.rb
Constant Summary collapse
- DISALLOWED_CHARACTERS =
"['?\\:]"
Instance Method Summary collapse
-
#add_normalization(expression) ⇒ Object
Applies configured accent normalization, preserving the input expression without an unaccent wrapper when accents are not ignored.
-
#initialize(config) ⇒ Normalizer
constructor
Arguments.
Constructor Details
#initialize(config) ⇒ Normalizer
Arguments
configSearch configuration whose ignore list controls accent normalization.
9 10 11 |
# File 'lib/pg_search/normalizer.rb', line 9 def initialize(config) @config = config end |
Instance Method Details
#add_normalization(expression) ⇒ Object
Applies configured accent normalization, preserving the input expression without an unaccent wrapper when accents are not ignored.
Arguments
expressionAn Arel node, attribute, or trusted SQL String. A String is an SQL expression, not a value to quote.
Returns a composable Arel expression.
Raises
- TypeError
If
expressionis not an Arel node, attribute, or String.
28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/pg_search/normalizer.rb', line 28 def add_normalization(expression) node = to_node(expression) return node unless config.ignore.include?(:accents) Arel::Nodes::NamedFunction.new( "regexp_replace", [ Arel::Nodes::NamedFunction.new(PgSearch.unaccent_function, [node]), Arel::Nodes.build_quoted(DISALLOWED_CHARACTERS), Arel::Nodes.build_quoted(""), Arel::Nodes.build_quoted("g") ] ) end |