Sushrit Pasupuleti
Sushrit Pasupuleti

Reputation: 155

Fulltext search using Sequelize (Postgres)

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!

Upvotes: 4

Views: 2878

Answers (1)

Anatoly
Anatoly

Reputation: 22758

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

Upvotes: 6

Related Questions