Skip to content
This repository has been archived by the owner on Sep 13, 2021. It is now read-only.

Commit

Permalink
feat: use fulltext search in cahrts API
Browse files Browse the repository at this point in the history
  • Loading branch information
gka committed Sep 6, 2021
1 parent 8aaba3c commit 76c8d6f
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/routes/charts/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const Joi = require('joi');
const { Op } = require('@datawrapper/orm').db;
const { Op, literal } = require('@datawrapper/orm').db;
const { decamelizeKeys, decamelize } = require('humps');
const set = require('lodash/set');
const { Chart, User } = require('@datawrapper/orm/models');
Expand Down Expand Up @@ -184,12 +184,12 @@ async function getAllCharts(request, h) {

if (query.search) {
const search = [
{ title: { [Op.like]: `%${query.search}%` } },
{ metadata: { describe: { intro: { [Op.like]: `%${query.search}%` } } } },
{ metadata: { describe: { byline: { [Op.like]: `%${query.search}%` } } } },
{ metadata: { describe: { 'source-name': { [Op.like]: `%${query.search}%` } } } },
{ metadata: { describe: { 'source-url': { [Op.like]: `%${query.search}%` } } } },
{ metadata: { annotate: { notes: { [Op.like]: `%${query.search}%` } } } }
literal(
`MATCH(title, keywords) AGAINST ('${query.search.replace(
/'/g,
''
)}' IN BOOLEAN MODE)`
)
];
set(options, ['where', Op.or], search);
}
Expand Down

0 comments on commit 76c8d6f

Please sign in to comment.