-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature-[167940543]: Implement global search
- Extend search feature to allow searching all models with one query [Delivers #167940543]
- Loading branch information
Showing
10 changed files
with
181 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
const vectorName = '_search'; | ||
|
||
const searchObjects = { | ||
Articles: ['title', '"articleBody"', 'description'], | ||
Tags: ['name'] | ||
}; | ||
|
||
export default { | ||
up: queryInterface => queryInterface.sequelize.transaction(t => Promise.all( | ||
Object.keys(searchObjects).map(table => queryInterface.sequelize | ||
.query( | ||
` | ||
ALTER TABLE "${table}" ADD COLUMN ${vectorName} TSVECTOR; | ||
`, | ||
{ transaction: t } | ||
) | ||
.then(() => queryInterface.sequelize.query( | ||
` | ||
UPDATE "${table}" SET ${vectorName} = | ||
to_tsvector('english', ${searchObjects[table].join( | ||
" || ' ' || " | ||
)}); | ||
`, | ||
{ transaction: t } | ||
)) | ||
.then(() => queryInterface.sequelize.query( | ||
` | ||
CREATE INDEX "${table}_search" ON "${table}" USING gin(${vectorName}); | ||
`, | ||
{ transaction: t } | ||
)) | ||
.then(() => queryInterface.sequelize.query( | ||
` | ||
CREATE TRIGGER "${table}_vector_update" | ||
BEFORE INSERT OR UPDATE ON "${table}" | ||
FOR EACH ROW EXECUTE PROCEDURE tsvector_update_trigger(${vectorName}, | ||
'pg_catalog.english', ${searchObjects[table].join(', ')}); | ||
`, | ||
{ transaction: t } | ||
))) | ||
)), | ||
|
||
down: queryInterface => queryInterface.sequelize.transaction(t => Promise.all( | ||
Object.keys(searchObjects).map(table => queryInterface.sequelize | ||
.query( | ||
` | ||
DROP TRIGGER "${table}_vector_update" ON "${table}"; | ||
`, | ||
{ transaction: t } | ||
) | ||
.then(() => queryInterface.sequelize.query( | ||
` | ||
DROP INDEX "${table}_search"; | ||
`, | ||
{ transaction: t } | ||
)) | ||
.then(() => queryInterface.sequelize.query( | ||
` | ||
ALTER TABLE "${table}" DROP COLUMN ${vectorName}; | ||
`, | ||
{ transaction: t } | ||
))) | ||
)) | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters