[ARVADOS] updated: 3b39427f7fd70ac200aa2ead7f601d0a6d5166b1

git at public.curoverse.com git at public.curoverse.com
Mon Feb 10 16:15:19 EST 2014


Summary of changes:
 services/api/app/models/arvados_model.rb     |   26 ++++++++++++++++++++++----
 services/api/app/models/collection.rb        |    2 +-
 services/api/app/models/group.rb             |    2 +-
 services/api/app/models/human.rb             |    2 +-
 services/api/app/models/job.rb               |    2 +-
 services/api/app/models/job_task.rb          |    2 +-
 services/api/app/models/link.rb              |    2 +-
 services/api/app/models/log.rb               |    2 +-
 services/api/app/models/pipeline_instance.rb |    2 +-
 services/api/app/models/specimen.rb          |    2 +-
 services/api/app/models/trait.rb             |    2 +-
 11 files changed, 32 insertions(+), 14 deletions(-)

       via  3b39427f7fd70ac200aa2ead7f601d0a6d5166b1 (commit)
      from  18267d52438fb1ece23135755da9f6881e32b99f (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.


commit 3b39427f7fd70ac200aa2ead7f601d0a6d5166b1
Author: Tim Pierce <twp at curoverse.com>
Date:   Mon Feb 10 16:15:51 2014 -0500

    Added ArvadosModel.search_for_user to perform full-text search on a model.

diff --git a/services/api/app/models/arvados_model.rb b/services/api/app/models/arvados_model.rb
index 5cbfd58..4e406de 100644
--- a/services/api/app/models/arvados_model.rb
+++ b/services/api/app/models/arvados_model.rb
@@ -45,13 +45,31 @@ class ArvadosModel < ActiveRecord::Base
     end.compact
   end
 
-  # is_searchable returns 'true' if a model is subject to full-text
-  # search through the workbench.  Models which are searchable should
-  # return true.
-  def is_searchable
+  # searchable? indicates whether a model is subject to full-text
+  # search through the workbench.  Models which include data that is
+  # interesting to a full-text search (e.g. Collection, Specimen, Trait)
+  # should override this to return 'true'.
+  def self.searchable?
     false
   end
 
+  # search all "searchable" columns of this table for query_str.
+  def self.search_for_user(user, query_str)
+    return [] unless self.searchable?
+    ilikes = []
+    ilike_params = []
+    self.searchable_columns.each do |column|
+      ilikes << "#{table_name}.#{column} ilike ?"
+      ilike_params << "%#{query_str}%"
+    end
+    if ilikes.empty?
+      return []
+    else
+      query_conditions = [ ilikes.join(' or ') ] + ilike_params
+      return self.readable_by(user).where(query_conditions)
+    end
+  end
+
   def eager_load_associations
     self.class.columns.each do |col|
       re = col.name.match /^(.*)_kind$/
diff --git a/services/api/app/models/collection.rb b/services/api/app/models/collection.rb
index c6ecee3..76bc3a0 100644
--- a/services/api/app/models/collection.rb
+++ b/services/api/app/models/collection.rb
@@ -8,7 +8,7 @@ class Collection < ArvadosModel
     t.add :files
   end
 
-  def is_searchable
+  def self.searchable?
     true
   end
 
diff --git a/services/api/app/models/group.rb b/services/api/app/models/group.rb
index 7a1c9fb..e989218 100644
--- a/services/api/app/models/group.rb
+++ b/services/api/app/models/group.rb
@@ -8,7 +8,7 @@ class Group < ArvadosModel
     t.add :description
   end
 
-  def is_searchable
+  def self.searchable?
     true
   end
 end
diff --git a/services/api/app/models/human.rb b/services/api/app/models/human.rb
index a87a041..5e0abb5 100644
--- a/services/api/app/models/human.rb
+++ b/services/api/app/models/human.rb
@@ -8,7 +8,7 @@ class Human < ArvadosModel
     t.add :properties
   end
 
-  def is_searchable
+  def self.searchable?
     true
   end
 end
diff --git a/services/api/app/models/job.rb b/services/api/app/models/job.rb
index 4a05f6b..71b006d 100644
--- a/services/api/app/models/job.rb
+++ b/services/api/app/models/job.rb
@@ -37,7 +37,7 @@ class Job < ArvadosModel
     t.add :log_stream_href
   end
 
-  def is_searchable
+  def self.searchable?
     true
   end
 
diff --git a/services/api/app/models/job_task.rb b/services/api/app/models/job_task.rb
index 03310cc..611848d 100644
--- a/services/api/app/models/job_task.rb
+++ b/services/api/app/models/job_task.rb
@@ -17,7 +17,7 @@ class JobTask < ArvadosModel
     t.add :success
   end
 
-  def is_searchable
+  def self.searchable?
     true
   end
 
diff --git a/services/api/app/models/link.rb b/services/api/app/models/link.rb
index 3c701bf..0db41c7 100644
--- a/services/api/app/models/link.rb
+++ b/services/api/app/models/link.rb
@@ -29,7 +29,7 @@ class Link < ArvadosModel
     super
   end
 
-  def is_searchable
+  def self.searchable?
     true
   end
 
diff --git a/services/api/app/models/log.rb b/services/api/app/models/log.rb
index 3e52395..5b2e027 100644
--- a/services/api/app/models/log.rb
+++ b/services/api/app/models/log.rb
@@ -16,7 +16,7 @@ class Log < ArvadosModel
     t.add :info
   end
 
-  def is_searchable
+  def self.searchable?
     true
   end
 
diff --git a/services/api/app/models/pipeline_instance.rb b/services/api/app/models/pipeline_instance.rb
index 5df8756..a46085e 100644
--- a/services/api/app/models/pipeline_instance.rb
+++ b/services/api/app/models/pipeline_instance.rb
@@ -21,7 +21,7 @@ class PipelineInstance < ArvadosModel
     t.add :properties
   end
 
-  def is_searchable
+  def self.searchable?
     true
   end
 
diff --git a/services/api/app/models/specimen.rb b/services/api/app/models/specimen.rb
index 37de071..5b9e819 100644
--- a/services/api/app/models/specimen.rb
+++ b/services/api/app/models/specimen.rb
@@ -9,7 +9,7 @@ class Specimen < ArvadosModel
     t.add :properties
   end
 
-  def is_searchable
+  def self.searchable?
     true
   end
 
diff --git a/services/api/app/models/trait.rb b/services/api/app/models/trait.rb
index ff3db80..53c62a7 100644
--- a/services/api/app/models/trait.rb
+++ b/services/api/app/models/trait.rb
@@ -9,7 +9,7 @@ class Trait < ArvadosModel
     t.add :properties
   end
 
-  def is_searchable
+  def self.searchable?
     true
   end
 end

-----------------------------------------------------------------------


hooks/post-receive
-- 




More information about the arvados-commits mailing list