d2b549a53508b69941a082424a135de51ba2f15d
[arvados.git] / apps / workbench / app / assets / javascripts / ilike_filters.js
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 // ilike_filters() converts a user-entered search query to a list of
6 // filters using the newly added (as of Arvados 1.5) trigram indexes. It returns
7 // [] (empty list) if it can't come up with anything valid (e.g., q consists
8 // entirely of punctuation).
9 //
10 // Examples:
11 //
12 // "foo"     => [["any", "ilike", "%foo%"]]
13 // "foo.bar" => [["any", "ilike", "%foo.bar%"]]                         // "." is a word char in ilike queries
14 // "foo/b-r" => [["any", "ilike", "%foo/b-r%"]]                         // "/" and "-", too
15 // "foo bar" => [["any", "ilike", "%foo%"], ["any", "ilike", "%bar%"]]
16 // "foo|bar" => [["any", "ilike", "%foo%"], ["any", "ilike", "%bar%"]]
17 // " oo|bar" => [["any", "ilike", "%oo%"], ["any", "ilike", "%bar%"]]
18 // ""        => []
19 // " "       => []
20 // null      => []
21 window.ilike_filters = function(q) {
22     q = (q || '').replace(/[^-\w\.\/]+/g, ' ').trim()
23     if (q == '')
24         return []
25     return q.split(" ").map(function(term) {
26         return ["any", "ilike", "%"+term+"%"]
27     })
28 }