Skip to content

Commit

Permalink
fix: more fts fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
mkeen committed Jan 5, 2022
1 parent 32bc2b0 commit 8ace0d9
Showing 1 changed file with 20 additions and 12 deletions.
32 changes: 20 additions & 12 deletions src/models/projects/projects.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,16 +76,20 @@ class Project extends Model {
if (orgUid) {
sql = `${sql} AND orgUid = :orgUid`;
}

sql = `${sql} ORDER BY relevance DESC LIMIT :limit OFFSET :offset`;

const count = await Project.count();

const replacements = { search: searchStr, orgUid };

const count = (await sequelize.query(sql, {
model: Project,
mapToModel: true, // pass true here if you have any mapped fields
replacements
})).length;

return {
count,
rows: await sequelize.query(sql, {
rows: await sequelize.query(`${sql} ORDER BY relevance DESC LIMIT :limit OFFSET :offset`, {
model: Project,
replacements: { search: searchStr, orgUid, offset, limit },
replacements: {...replacements, ...{offset, limit}},
mapToModel: true, // pass true here if you have any mapped fields
}),
};
Expand All @@ -98,17 +102,21 @@ class Project extends Model {
if (orgUid) {
sql = `${sql} AND orgUid = :orgUid`;
}

sql = `${sql} ORDER BY rank DESC LIMIT :limit OFFSET :offset`;
const replacements = { search: `${searchStr}*`, orgUid };

const count = await Project.count();

const count = (await sequelize.query(sql, {
model: Project,
mapToModel: true, // pass true here if you have any mapped fields
replacements
})).length;

return {
count,
rows: sequelize.query(sql, {
rows: await sequelize.query(`${sql} ORDER BY rank DESC LIMIT :limit OFFSET :offset`, {
model: Project,
replacements: { search: `${searchStr}*`, orgUid, offset, limit },
mapToModel: true, // pass true here if you have any mapped fields
replacements: {...replacements, ...{offset, limit}}
}),
};
}
Expand Down

0 comments on commit 8ace0d9

Please sign in to comment.