With where={"any":["contains",X]}, search all text and string columns.
authorTom Clegg <tom@curoverse.com>
Wed, 15 Jan 2014 05:13:32 +0000 (21:13 -0800)
committerTom Clegg <tom@curoverse.com>
Wed, 15 Jan 2014 05:13:32 +0000 (21:13 -0800)
closes #1867

apps/workbench/app/controllers/collections_controller.rb
services/api/app/controllers/application_controller.rb
services/api/app/models/arvados_model.rb

index fe861eb87d69068f7a2007217fb1a68859bd5492..447b34d1ffaf514678f3603bbeeeaa115f44555c 100644 (file)
@@ -8,8 +8,10 @@ class CollectionsController < ApplicationController
 
   def index
     if params[:search].andand.length.andand > 0
-      tags = Link.where(link_class: 'tag', any: ['contains', params[:search]])
-      @collections = Collection.where(uuid: tags.collect(&:head_uuid))
+      tags = Link.where(any: ['contains', params[:search]])
+      @collections = (Collection.where(uuid: tags.collect(&:head_uuid)) |
+                      Collection.where(any: ['contains', params[:search]])).
+        uniq { |c| c.uuid }
     else
       @collections = Collection.limit(100)
     end
index 708defede671ac6fc60af73fd83485fcdfd31545..2b7b34b18d15677b9f66c6133a21726051115bf3 100644 (file)
@@ -129,8 +129,14 @@ class ApplicationController < ActionController::Base
           if value.is_a?(Array) and
               value[0] == 'contains' and
               model_class.columns.collect(&:name).index('name') then
-            conditions[0] << " and #{table_name}.name ilike ?"
-            conditions << "%#{value[1]}%"
+            ilikes = []
+            model_class.searchable_columns.each do |column|
+              ilikes << "#{table_name}.#{column} ilike ?"
+              conditions << "%#{value[1]}%"
+            end
+            if ilikes.any?
+              conditions[0] << ' and (' + ilikes.join(' or ') + ')'
+            end
           end
         elsif attr.to_s.match(/^[a-z][_a-z0-9]+$/) and
             model_class.columns.collect(&:name).index(attr.to_s)
index 991755b48a67f9803bbcdf415c1552c09dec1ba2..2999b5271331ed9d11ef382fb826350d6646e417 100644 (file)
@@ -36,6 +36,14 @@ class ArvadosModel < ActiveRecord::Base
     "#{current_api_base}/#{self.class.to_s.pluralize.underscore}/#{self.uuid}"
   end
 
+  def self.searchable_columns
+    self.columns.collect do |col|
+      if [:string, :text].index(col.type) && col.name != 'owner_uuid'
+        col.name
+      end
+    end.compact
+  end
+
   def eager_load_associations
     self.class.columns.each do |col|
       re = col.name.match /^(.*)_kind$/