15429: Removes unused to_tsquery()
[arvados.git] / apps / workbench / app / assets / javascripts / to_tsquery.js
index fc05b2675866da6304a1a58fd107e3273996dbfb..6957a5fe8f125257cabcd0c5ec66d682d5899c01 100644 (file)
@@ -2,22 +2,27 @@
 //
 // SPDX-License-Identifier: AGPL-3.0
 
-// to_tsquery() converts a user-entered search query to a useful
-// operand for the Arvados API "@@" filter. It returns null if it
-// can't come up with anything valid (e.g., q consists entirely of
+// to_tsquery_filters() converts a user-entered search query to a list of
+// filters using the newly added (as for arvados 1.5) trigram indexes. It returns
+// null if it can't come up with anything valid (e.g., q consists entirely of
 // punctuation).
 //
 // Examples:
 //
-// "foo"     => "foo:*"
-// "foo/bar" => "foo:*&bar:*"
-// "foo|bar" => "foo:*&bar:*"
-// " oo|ba " => "oo:*&ba:*"
-// "// "     => null
-// ""        => null
-window.to_tsquery = function(q) {
-    q = (q || '').replace(/\W+/g, ' ').trim().replace(/ /g, ':*&')
+// "foo"     => [["any", "ilike", "%foo%"]]
+// "foo.bar" => [["any", "ilike", "%foo.bar%"]]                         // "." is a word char in FT queries
+// "foo/b-r" => [["any", "ilike", "%foo/b-r%"]]                         // "/" and "-", too
+// "foo bar" => [["any", "ilike", "%foo%"], ["any", "ilike", "%bar%"]]
+// "foo|bar" => [["any", "ilike", "%foo%"], ["any", "ilike", "%bar%"]]
+// " oo|bar" => [["any", "ilike", "%oo%"], ["any", "ilike", "%bar%"]]
+// ""        => []
+// " "       => []
+// null      => []
+window.to_tsquery_filters = function(q) {
+    q = (q || '').replace(/[^-\w\.\/]+/g, ' ').trim()
     if (q == '')
-        return null
-    return q + ':*'
-}
+        return []
+    return q.split(" ").map(function(term) {
+        return ["any", "ilike", "%"+term+"%"]
+    })
+}
\ No newline at end of file