From e80461544faf7ca7e8f46ff9a60cf6fa1f75a1e9 Mon Sep 17 00:00:00 2001 From: Felix Ruiz de Arcaute Date: Fri, 8 May 2020 18:45:18 +0200 Subject: [PATCH] Attempt to allow fuzzy-match filter in fortune-postgres Notes ----- I am unsure what field of options may be used. The options.query already seemed to be used, so started looking for another field. As I understand it, Adapter.find leaves the possibility of extra fields on the options object unspecified. Therefore, I added the fuzzyMatch field. --- lib/index.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib/index.js b/lib/index.js index 865e963..6388ebd 100644 --- a/lib/index.js +++ b/lib/index.js @@ -310,6 +310,14 @@ module.exports = Adapter => class PostgreSQLAdapter extends Adapter { } } + for (const field in options.fuzzyMatch) { + let value = options.fuzzyMatch[field] + //We assume the request has been validaded on another level. (so only strings, no arrays, etc...) + index++ + parameters.push(inputValue(value)) + where.push(`"${field}" ~* $${index}`) + } + where = where.length ? `where ${where.join(' and ')}` : '' for (const field in options.sort) {