From 77b06b8356a1a8f0f703cff708ab7abd13a9f66f Mon Sep 17 00:00:00 2001 From: Greg Date: Tue, 10 Jan 2023 20:21:51 -0800 Subject: [PATCH] add fulltext operator --- README.md | 19 +++++++++++++++++++ lib/index.js | 5 +++-- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 773abab..da37cbe 100644 --- a/README.md +++ b/README.md @@ -288,6 +288,25 @@ Through the REST API: /messages?label[$overlap][0]=important&label[$overlap][1]=work&label[$overlap][2]=urgent ``` +### $fulltext + +For PostgreSQL only, for fulltext-indexed fields, finds records that match useing postgres' fulltext natural-langauge search. The following query retrieves all messages whose labels contain any of the values `important`, `work`, or `urgent`, but no values outside that list : + +```js +app.service('messages').find({ + query: { + labels: { + $contained_by: ['important', 'work', 'urgent'] + } + } +}); +``` + +Through the REST API: + +``` +/messages?label[$contained_by][0]=important&label[$contained_by][1]=work&label[$contained_by][2]=urgent +``` ## Transaction Support diff --git a/lib/index.js b/lib/index.js index 8e99190..e9fb1bb 100644 --- a/lib/index.js +++ b/lib/index.js @@ -26,7 +26,8 @@ const OPERATORS = { $ilike: 'ilike', $overlap: '&&', $contains: '@>', - $contained_by: '<@' + $contained_by: '<@', + $fulltext: '@@' }; // Create the service. @@ -45,7 +46,7 @@ class Service extends AdapterService { super(Object.assign({ id: 'id' }, options, { - whitelist: whitelist.concat(['$like', '$notlike', '$ilike', '$and', '$overlap', '$contains', '$contained_by']) + whitelist: whitelist.concat(['$like', '$notlike', '$ilike', '$and', '$overlap', '$contains', '$contained_by', '$fulltext']) })); this.table = options.name;