Fix 2.4.2 upgrade notes formatting refs #19330
[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\\_bar%"]                        // "_" should be escaped so it can be used as a literal
16 // "foo bar" => [["any", "ilike", "%foo%"], ["any", "ilike", "%bar%"]]
17 // "foo|bar" => [["any", "ilike", "%foo%"], ["any", "ilike", "%bar%"]]
18 // " oo|bar" => [["any", "ilike", "%oo%"], ["any", "ilike", "%bar%"]]
19 // ""        => []
20 // " "       => []
21 // null      => []
22 window.ilike_filters = function(q) {
23     q = (q || '').replace(/[^-\w\.\/]+/g, ' ').trim().replace(/_/g, '\\_')
24     if (q == '')
25         return []
26     return q.split(" ").map(function(term) {
27         return ["any", "ilike", "%"+term+"%"]
28     })
29 }