15429: Changes full text searching on wb1 utilizing new trigram indexes.
[arvados.git] / apps / workbench / app / assets / javascripts / to_tsquery.js
index ab584d4be6682088b2c5d396dc2d28fe21b40006..dbb17f3f734e09ae14504d07752805999f548b14 100644 (file)
 // Examples:
 //
 // "foo"     => "foo:*"
-// "foo/bar" => "foo:*&bar:*"
+// "foo_bar" => "foo:*&bar:*"
+// "foo.bar" => "foo.bar:*"    // "." is a word char in FT queries
+// "foo/b-r" => "foo/b-r:*"    // "/" and "-", too
 // "foo|bar" => "foo:*&bar:*"
 // " oo|ba " => "oo:*&ba:*"
-// "// "     => null
+// "__ "     => null
 // ""        => null
 // null      => null
 window.to_tsquery = function(q) {
-    q = (q || '').replace(/\W+/g, ' ').trim().replace(/ /g, ':*&')
+    q = (q || '').replace(/[^-\w\.\/]+/g, ' ').trim().replace(/ /g, ':*&')
     if (q == '')
         return null
     return q + ':*'
 }
+
+// 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.
+//
+// Examples:
+//
+// "foo"     => [["any", "ilike", "%foo%"]]
+// "foo.bar" => [["any", "ilike", "%foo.bar%"]]
+// "foo bar" => [["any", "ilike", "%foo%"], ["any", "ilike", "%bar%"]]
+// "foo|bar" => [["any", "ilike", "%foo%"], ["any", "ilike", "%bar%"]]
+// ""        => []
+// null      => []
+window.to_tsquery_filters = function(q) {
+    q = (q || '').replace(/[^-\w\.\/]+/g, ' ').trim()
+    if (q == '')
+        return []
+    return q.split(" ").map(function(term) {
+        return ["any", "ilike", "%"+term+"%"]
+    })
+}
\ No newline at end of file