Skip to content

Feature : Specifying the row language for to_tsvector call. #47

@ibrahim12

Description

@ibrahim12

Provision for setting regconfig as a row column.

like on model,

class Post(db.Model):
   ...
   title = db.Column(db.String)
   ketwords = db.Column(db.Text)

   # will hold for language full name for each row.
   row_language = db.Column(db.String, defualt='english' )
   search_vector = db.Column(TSVectorType('keywords', 'title', regconfig='post.row_language'))

on migrations,

    sync_trigger(conn, 'post', 'search_vector', ['keywords', 'title'], None, {regconfig: 'post.row_language'} )

This will generate a query like this,

SELECT *
FROM table
WHERE search_vector @@ to_tsquery(post.row_langugage::regconfig, 'SEARCH_KEY') ;

Trigger will be,

BEGIN
                NEW.search_vector = to_tsvector(post.row_language::regconfig, regexp_replace(coalesce(NEW.keywords, ''''), ''[-@.]'', '' '', ''g'')) || to_tsvector(post.row_language::regconfig, regexp_replace(coalesce(NEW.title, ''''), ''[-@.]'', '' '', ''g''));
                RETURN NEW;
END

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