You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
dialect: postgresFor issues and PRs. Things that involve PostgreSQL (and do not involve all dialects).status: wipFor issues and PRs. Applied when the PR is not ready yet / when work to close the issue has started.type: featureDEPRECATED: replace with the "feature" issue type
Reacted by Madison Rickert, Kennet Postigo, Marc Harter, James Maidment, Samy Al Zahrani, Mujtaba Al-Tameemi, fogine, Pavel Pokorný, Jack Turnbull, asyncopation and 32 more
The method on mathisonian.com is a good start, but because it uses a custom function text searches can't be combined with other search queries. If you wanted to search for posts containing X by user Y you'd need to filter for user Y separately.
One option which may be quicker to implement (but might be slower) would be to use an index rather than a separate column. But the index might use less disk space.
Ideally it would be possible to set weights for different columns when combining them into one index/TSVECTOR column.
Please don't +1 issues. It clutters the thread without adding value to the discussion and spams maintainers with notifications. Use GitHub reactions to upvote features.
Reacted by Dannii Willis, Alexis Benoist, Mujtaba Al-Tameemi, Uladzislau Vavilau, Sharad K, David Daniel, Grigory Shepelev, Alejo Mendoza, Clipmedia General, Aaron Chou and 20 more
Reacted by Aaron McGuire
Reacted by Aaron McGuire, Andrew Aladjev and Philipp Berger ;)
Reacted by Marc Schipperheyn, A. Campbell, Rory Hughes, Leandro Hoffmann, David, 胡玮文, Jerome S., Alessandro Dal Grande, Øyvind Eide, PikaDude and 9 more
@mschipperheyn Here is a custom migration that creates a column for storing ts vector, adds an index for the same and creates a trigger where you specify the list of columns in your table from which the ts vector is generated
Use the Sequelize CLI to generate a new migration with the command below ./node_modules/.bin/sequelize migration:create --name add-tsvector-to-feed-item-title-description
Open the file
Feel free to replace the column names and table name with whatever you want
module.exports={// eslint-disable-next-line no-unused-varsup: (queryInterface,Sequelize)=>{/* Add altering commands here. Return a promise to correctly handle asynchronicity. Example: return queryInterface.createTable('users', { id: Sequelize.INTEGER }); */const{ sequelize }=queryInterface;constsearchFields=['title','summary'];constvectorName='title_summary_vector';consttableName='feed_items';constindexName='title_summary_vector_search_idx';consttriggerName='title_summary_vector_update';returnsequelize.query(`ALTER TABLE "${tableName}" ADD COLUMN "${vectorName}" TSVECTOR`).then(()=>{console.log('Column added: Adding updating values');returnsequelize.query(`UPDATE "${tableName}" SET "${vectorName}" = to_tsvector('english', ${searchFields.join(' || \' \' || ')})`).catch(console.log);}).then(()=>{console.log('Values added: Creating Index');returnsequelize.query(`CREATE INDEX ${indexName} ON "${tableName}" USING gin("${vectorName}");`).catch(console.log);}).then(()=>{console.log('Index created: Adding trigger');returnsequelize.query(`CREATE TRIGGER ${triggerName} BEFORE INSERT OR UPDATE ON "${tableName}" FOR EACH ROW EXECUTE PROCEDURE tsvector_update_trigger("${vectorName}", 'pg_catalog.english', ${searchFields.join(', ')})`).catch(console.log);}).then(()=>{console.log('Everything worked!');}).catch(console.log);},// eslint-disable-next-line no-unused-varsdown: (queryInterface,Sequelize)=>{/* Add reverting commands here. Return a promise to correctly handle asynchronicity. Example: return queryInterface.dropTable('users'); */const{ sequelize }=queryInterface;constvectorName='title_summary_vector';consttableName='feed_items';constindexName='title_summary_vector_search_idx';consttriggerName='title_summary_vector_update';returnsequelize.query(`DROP TRIGGER ${triggerName} ON "${tableName}"`).then(()=>{console.log('removed trigger');returnsequelize.query(`DROP INDEX ${indexName}`).catch(console.log);}).then(()=>{console.log('removed index');returnsequelize.query(`ALTER TABLE "${tableName}" DROP COLUMN "${vectorName}"`).catch(console.log);}).then(()=>{console.log('removed column');}).catch(console.log);},};
Run the migration ./node_modules/.bin/sequelize db:migrate
Boom, you got ts vector support ON, you dont need to modify your insert or update queries in any way as the trigger does it
@papb sorry, I lost track of this issue. I use MySql. The only reason I'm still on sequelize v4 is because it offers an escape hatch that permits me to hack
Sequelize.literal(`MATCH (\someColumn\) AGAINST('someValue*' IN BOOLEAN MODE)`)`)
which was blocked in v5 I think. full text search is a really useful alternative to implementing elastic search. Especially for simpler use cases like filtering table lists. Unfortunately, the approach between Postgres and MySql is completely different. It would be awesome if Sequelize would abstract this difference away but given the differences in approach between postgres and MySql not the easiest thing to implement. Personally, I find the approach MySql uses much more intuitive than the Postgres version.
Since I don't use raw here, I don't remember if my decision to not upgrade to v5 is unfounded :-D
Reacted by songkeys, Leandro Finger and Jromeroc90
dialect: postgresFor issues and PRs. Things that involve PostgreSQL (and do not involve all dialects).status: wipFor issues and PRs. Applied when the PR is not ready yet / when work to close the issue has started.type: featureDEPRECATED: replace with the "feature" issue type
Activity
Toub commentedon Feb 18, 2015
+1
Related article: http://www.mathisonian.com/weblog/postgres-full-text-search-with-sequelizejs
bleupen commentedon May 11, 2015
curiousdannii commentedon Jun 8, 2015
The method on mathisonian.com is a good start, but because it uses a custom function text searches can't be combined with other search queries. If you wanted to search for posts containing X by user Y you'd need to filter for user Y separately.
One option which may be quicker to implement (but might be slower) would be to use an index rather than a separate column. But the index might use less disk space.
Ideally it would be possible to set weights for different columns when combining them into one index/TSVECTOR column.
drouillard commentedon Oct 2, 2015
mujz commentedon Jul 7, 2016
mjurincic commentedon Jul 7, 2016
mhoffman commentedon Nov 11, 2016
felixfbecker commentedon Nov 11, 2016
Please don't +1 issues. It clutters the thread without adding value to the discussion and spams maintainers with notifications. Use GitHub reactions to upvote features.

feat(query-generator): add @@ operator (sequelize#1580)
6 remaining items
schettino commentedon Mar 31, 2018
Any news about it?
mschipperheyn commentedon May 3, 2019
This is preventing me from upgrading to v5 because
rawoperations are no longer supported.jnelken commentedon May 26, 2019
Looks like attempts are being made. Let's contribute! #1580
slidenerd commentedon Oct 3, 2019
@mschipperheyn Here is a custom migration that creates a column for storing ts vector, adds an index for the same and creates a trigger where you specify the list of columns in your table from which the ts vector is generated
Use the Sequelize CLI to generate a new migration with the command below
./node_modules/.bin/sequelize migration:create --name add-tsvector-to-feed-item-title-descriptionOpen the file
Feel free to replace the column names and table name with whatever you want
Run the migration
./node_modules/.bin/sequelize db:migrateBoom, you got ts vector support ON, you dont need to modify your insert or update queries in any way as the trigger does it
papb commentedon Oct 30, 2019
It seemed to me that this request is postgres-only, is this correct?
papb commentedon Oct 30, 2019
@mschipperheyn What do you mean?
mschipperheyn commentedon Nov 11, 2019
@papb sorry, I lost track of this issue. I use MySql. The only reason I'm still on sequelize v4 is because it offers an escape hatch that permits me to hack
which was blocked in v5 I think. full text search is a really useful alternative to implementing elastic search. Especially for simpler use cases like filtering table lists. Unfortunately, the approach between Postgres and MySql is completely different. It would be awesome if Sequelize would abstract this difference away but given the differences in approach between postgres and MySql not the easiest thing to implement. Personally, I find the approach MySql uses much more intuitive than the Postgres version.
Since I don't use raw here, I don't remember if my decision to not upgrade to v5 is unfounded :-D
cauefernandes commentedon Apr 9, 2020
It works but the problem is that function won't use indexes.
papb commentedon Jan 27, 2021
Closed by #12955