Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
ibrahim12 opened this issue Apr 30, 2016 · 0 comments
Open

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

ibrahim12 opened this issue Apr 30, 2016 · 0 comments

Comments

@ibrahim12
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant