question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Postgresql tsvector field and query support

See original GitHub issue

Have you considered support for Postgresql’s tsvector type? ( https://www.postgresql.org/docs/12/textsearch.html )

I realize this would be entirely Postgresql specific so perhaps it would be more appropriate as a contrib module than a core feature.

I have been looking at implementing it and had a few different ideas; something like this perhaps:

  • custom Field which creates a tsvector column type
  • meta-field listing in a Model to describe which columns to full-text index
  • Add a CREATE TRIGGER to the schema generation for each tsvector field. For each insert to the table, invoke tsvector_update_trigger ( https://www.postgresql.org/docs/12/functions-textsearch.html ) for the new row to create the vector on the fields listed by your meta-field. This is the thing I’m least sure about; should this be implemented in Tortoise, or just use the database trigger to manage it?
  • custom query Function which allows for the ‘@@ tsquery’ syntax

One thing that Tortoise is missing is that it does not appear to be possible to tell Tortoise what index type you’d like when specifying to index a column; you would want to index the tsvector columns with either GIST or GIN depending on user requirements.

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:5
  • Comments:17 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
grigicommented, Mar 20, 2020

A special filter makes sense. I’m quite sick at the moment (and thinking is difficult), so I won’t get to anything soon. Possibly @abondar can help in the mean time if you want to attempt it?

0reactions
parkournerdcommented, Sep 22, 2021

I found that Postgres 12 added auto-generated and saved tsvectors: https://pgdash.io/blog/postgres-12-generated-columns.html. This could keep TsVectorField updated instead of using triggers. Seems like it almost fit into the generated_sql, but needs fields to compute from

Read more comments on GitHub >

github_iconTop Results From Across the Web

Documentation: 15: 8.11. Text Search Types - PostgreSQL
The tsvector type represents a document in a form optimized for text search; the tsquery type similarly represents a text query.
Read more >
Possible reason to include a tsvector field? - Stack Overflow
I have used the FTS capabilities in Postgres quite a bit, trigram, soundex, etc, too, and while it does work, we eventually decided...
Read more >
Mastering PostgreSQL Tools: Full-Text Search and Phrase ...
to_tsvector for creating a list of tokens (the tsvector data type, where ts stands for "text search");; to_tsquery for querying the vector ...
Read more >
Understanding PostgreSQL Full Text Search: 10 Critical Aspects
PostgreSQL Full Text Search also supports dictionaries that allow ... ALTER TABLE se_details ADD COLUMN ts tsvector GENERATED ALWAYS AS ...
Read more >
PostgreSQL® Full-Text Search - Instaclustr
The most comprehensive guide on how to master the PostgreSQL ... Once the tsvector column is set up, it can be used in...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found