Skip to content

Support for augmenting with websearch_to_tsquery, phraseto_tsquery, plainto_tsquery #552

@stv8

Description

@stv8

As seen here: https://www.postgresql.org/docs/current/textsearch-controls.html

class Post < ApplicationRecord
    pg_search_scope :search_by_title, against: :title
end
Post.search_by_title("word|word")
Post.search_by_title.phrase("somebody once told me the world was gonna roll me")
Post.search_by_title.plain("Shrek is the best")

def tsquery_for_term(unsanitized_term)
if options[:negation] && unsanitized_term.start_with?("!")
unsanitized_term[0] = ""
negated = true
end
sanitized_term = unsanitized_term.gsub(DISALLOWED_TSQUERY_CHARACTERS, " ")
term_sql = Arel.sql(normalize(connection.quote(sanitized_term)))
tsquery = tsquery_expression(term_sql, negated: negated, prefix: options[:prefix])
Arel::Nodes::NamedFunction.new("to_tsquery", [dictionary, tsquery]).to_sql

Maybe we can add an options hash here to swap out the desired function? I'm new to Ruby but this is my best guess.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions