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
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)
"#{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$/