ab584d4be6682088b2c5d396dc2d28fe21b40006
[arvados.git] / apps / workbench / app / assets / javascripts / to_tsquery.js
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 // to_tsquery() converts a user-entered search query to a useful
6 // operand for the Arvados API "@@" filter. It returns null if it
7 // can't come up with anything valid (e.g., q consists entirely of
8 // punctuation).
9 //
10 // Examples:
11 //
12 // "foo"     => "foo:*"
13 // "foo/bar" => "foo:*&bar:*"
14 // "foo|bar" => "foo:*&bar:*"
15 // " oo|ba " => "oo:*&ba:*"
16 // "// "     => null
17 // ""        => null
18 // null      => null
19 window.to_tsquery = function(q) {
20     q = (q || '').replace(/\W+/g, ' ').trim().replace(/ /g, ':*&')
21     if (q == '')
22         return null
23     return q + ':*'
24 }