From: Tom Clegg Date: Wed, 15 Jan 2014 05:13:32 +0000 (-0800) Subject: With where={"any":["contains",X]}, search all text and string columns. X-Git-Tag: 1.1.0~2722^2~80 X-Git-Url: https://git.arvados.org/arvados.git/commitdiff_plain/84f0a30a119355cd7deff1630a82d3d4c9a6d5ee?hp=5225a4deab9bf526d4e178cb5220f790b3d33e67 With where={"any":["contains",X]}, search all text and string columns. closes #1867 --- diff --git a/apps/workbench/app/controllers/collections_controller.rb b/apps/workbench/app/controllers/collections_controller.rb index fe861eb87d..447b34d1ff 100644 --- a/apps/workbench/app/controllers/collections_controller.rb +++ b/apps/workbench/app/controllers/collections_controller.rb @@ -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 diff --git a/services/api/app/controllers/application_controller.rb b/services/api/app/controllers/application_controller.rb index 708defede6..2b7b34b18d 100644 --- a/services/api/app/controllers/application_controller.rb +++ b/services/api/app/controllers/application_controller.rb @@ -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) diff --git a/services/api/app/models/arvados_model.rb b/services/api/app/models/arvados_model.rb index 991755b48a..2999b52713 100644 --- a/services/api/app/models/arvados_model.rb +++ b/services/api/app/models/arvados_model.rb @@ -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$/