Fulltext search using Sequelize (Postgres)

Viewed 1265

So I've been working with sequelize for a while now, and after juggling with elasticsearch, I decided to make use of postgres's support for fts.

It looks like just at the start of this year sequelize added support for TSVector which is necessary for FTS implementation. Although I just can't find any documentation whatsover anywhere.

The pull request

All help is appreciated!

1 Answers

If you look at changes for the PR you will see new operator Op.match and the new data type DateTypes.TSVECTOR. You can now define a field like this in a model:

...
textField: {
   type: DataTypes.TSVECTOR
}
...

And you simply can use it like this in where option:

textField: {
  [Op.match]: Sequelize.fn('to_tsquery', 'fat & rat') // match text search for strings 'fat' and 'rat' (PG only)
}

See this readme

Related