Add 'sdk/java-v2/' from commit '55f103e336ca9fb8bf1720d2ef4ee8dd4e221118'
[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:*"    // "." is a word char in FT queries
15 // "foo/b-r" => "foo/b-r:*"    // "/" and "-", too
16 // "foo|bar" => "foo:*&bar:*"
17 // " oo|ba " => "oo:*&ba:*"
18 // "__ "     => null
19 // ""        => null
20 // null      => null
21 window.to_tsquery = function(q) {
22     q = (q || '').replace(/[^-\w\.\/]+/g, ' ').trim().replace(/ /g, ':*&')
23     if (q == '')
24         return null
25     return q + ':*'
26 }