1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
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).
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%"]]
22 window.ilike_filters = function(q) {
23 q = (q || '').replace(/[^-\w\.\/]+/g, ' ').trim().replace(/_/g, '\\_')
26 return q.split(" ").map(function(term) {
27 return ["any", "ilike", "%"+term+"%"]