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

Commit 76c8d6f

Browse files
committed
feat: use fulltext search in cahrts API
1 parent 8aaba3c commit 76c8d6f

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

src/routes/charts/index.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const Joi = require('joi');
2-
const { Op } = require('@datawrapper/orm').db;
2+
const { Op, literal } = require('@datawrapper/orm').db;
33
const { decamelizeKeys, decamelize } = require('humps');
44
const set = require('lodash/set');
55
const { Chart, User } = require('@datawrapper/orm/models');
@@ -184,12 +184,12 @@ async function getAllCharts(request, h) {
184184

185185
if (query.search) {
186186
const search = [
187-
{ title: { [Op.like]: `%${query.search}%` } },
188-
{ metadata: { describe: { intro: { [Op.like]: `%${query.search}%` } } } },
189-
{ metadata: { describe: { byline: { [Op.like]: `%${query.search}%` } } } },
190-
{ metadata: { describe: { 'source-name': { [Op.like]: `%${query.search}%` } } } },
191-
{ metadata: { describe: { 'source-url': { [Op.like]: `%${query.search}%` } } } },
192-
{ metadata: { annotate: { notes: { [Op.like]: `%${query.search}%` } } } }
187+
literal(
188+
`MATCH(title, keywords) AGAINST ('${query.search.replace(
189+
/'/g,
190+
''
191+
)}' IN BOOLEAN MODE)`
192+
)
193193
];
194194
set(options, ['where', Op.or], search);
195195
}

0 commit comments

Comments
 (0)