15133: Re-add a stub crunch-dispatch.rb to make upgrade smoother
[arvados.git] / services / api / lib / record_filters.rb
index 9839413fcde3df58e036d82494c60f1dcfc3fec5..c8f024291c2c677c086445b294658a3c221211c0 100644 (file)
@@ -44,6 +44,14 @@ module RecordFilters
 
       cond_out = []
 
+      if attrs_in == 'any' && (operator.casecmp('ilike').zero? || operator.casecmp('like').zero?) && (operand.is_a? String) && operand.match('^[%].*[%]$')
+        # Trigram index search
+        cond_out << model_class.full_text_trgm + " #{operator} ?"
+        param_out << operand
+        # Skip the generic per-column operator loop below
+        attrs = []
+      end
+
       if operator == '@@'
         # Full-text search
         if attrs_in != 'any'
@@ -197,9 +205,14 @@ module RecordFilters
             operand.each do |op|
               cl = ArvadosModel::kind_class op
               if cl
-                if attr == 'uuid' and model_class.uuid_prefix == cl.uuid_prefix
-                  cond << "1=1"
+                if attr == 'uuid'
+                  if model_class.uuid_prefix == cl.uuid_prefix
+                    cond << "1=1"
+                  else
+                    cond << "1=0"
+                  end
                 else
+                  # Use a substring query to support remote uuids
                   cond << "substring(#{ar_table_name}.#{attr}, 7, 5) = ?"
                   param_out << cl.uuid_prefix
                 end