fix: Allow searching of previous document titles (#2326)
* Add migrations * Handle previousTitles when titles is updated * Add necessary test cases * Use previous title while searching * Rewrite logic to update previousTitles in beforeSave hook * Update weights * Update test to match new rank order * Add tooltip to inform user on document * Add code comment * Remove previous title tooltip * fix: Remove unused string, add model tests Co-authored-by: Tom Moor <tom.moor@gmail.com>
This commit is contained in:
13
server/migrations/20210716064654-introduce-previousTitles.js
Normal file
13
server/migrations/20210716064654-introduce-previousTitles.js
Normal file
@@ -0,0 +1,13 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = {
|
||||
up: async (queryInterface, Sequelize) => {
|
||||
await queryInterface.addColumn("documents","previousTitles",{
|
||||
type: Sequelize.ARRAY(Sequelize.STRING)
|
||||
})
|
||||
},
|
||||
|
||||
down: async (queryInterface, Sequelize) => {
|
||||
await queryInterface.removeColumn("documents", "previousTitles");
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,33 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = {
|
||||
up: async (queryInterface, Sequelize) => {
|
||||
const searchDocument = `
|
||||
CREATE OR REPLACE FUNCTION documents_search_trigger() RETURNS trigger AS $$
|
||||
begin
|
||||
new."searchVector" :=
|
||||
setweight(to_tsvector('english', coalesce(new.title, '')),'A') ||
|
||||
setweight(to_tsvector('english', coalesce(array_to_string(new."previousTitles", ' , '),'')),'C') ||
|
||||
setweight(to_tsvector('english', coalesce(new.text, '')), 'B');
|
||||
return new;
|
||||
end
|
||||
$$ LANGUAGE plpgsql;
|
||||
`;
|
||||
await queryInterface.sequelize.query(searchDocument);
|
||||
},
|
||||
|
||||
down: async (queryInterface, Sequelize) => {
|
||||
const searchDocument = `
|
||||
CREATE OR REPLACE FUNCTION documents_search_trigger() RETURNS trigger AS $$
|
||||
begin
|
||||
new."searchVector" :=
|
||||
setweight(to_tsvector('english', coalesce(new.title, '')),'A') ||
|
||||
setweight(to_tsvector('english', coalesce(new.text, '')), 'C');
|
||||
return new;
|
||||
end
|
||||
$$ LANGUAGE plpgsql;
|
||||
`;
|
||||
await queryInterface.sequelize.query(searchDocument);
|
||||
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user