From f721441f11376cb4286f12c0d959e48ca4488227 Mon Sep 17 00:00:00 2001 From: Robert Best Date: Tue, 18 Feb 2014 23:33:09 -0500 Subject: [PATCH] Update main_controller.rb Made edits to what results end up in the @topics array... THis should add more results, and not exclude incorrectly... and I made the default to search the desc and the link text too. I hope I have done the array manipulation right with: @topics = @topics + (@topics2 - @topics) --- app/controllers/main_controller.rb | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/app/controllers/main_controller.rb b/app/controllers/main_controller.rb index 6f86ccfa..3ea6cb77 100644 --- a/app/controllers/main_controller.rb +++ b/app/controllers/main_controller.rb @@ -65,12 +65,26 @@ class MainController < ApplicationController if term == "" @topics = [] else - search = '%' + term.downcase + '%' + search = term.downcase + '%' if !user @topics = Topic.where('LOWER("name") like ?', search).where('metacode_id = ?', filterByMetacode.id).order('"name"') + @topics2 = Topic.where('LOWER("name") like ?', '%' + search).where('metacode_id = ?', filterByMetacode.id).order('"name"') + @topics3 = Topic.where('LOWER("desc") like ?', '%' + search).where('metacode_id = ?', filterByMetacode.id).order('"name"') + @topics4 = Topic.where('LOWER("link") like ?', '%' + search).where('metacode_id = ?', filterByMetacode.id).order('"name"') + @topics = @topics + (@topics2 - @topics) + @topics = @topics + (@topics3 - @topics) + @topics = @topics + (@topics4 - @topics) + elsif user @topics = Topic.where('LOWER("name") like ?', search).where('metacode_id = ? AND user_id = ?', filterByMetacode.id, user).order('"name"') + @topics2 = Topic.where('LOWER("name") like ?', '%' + search).where('metacode_id = ? AND user_id = ?', filterByMetacode.id, user).order('"name"') + @topics3 = Topic.where('LOWER("desc") like ?', '%' + search).where('metacode_id = ? AND user_id = ?', filterByMetacode.id, user).order('"name"') + @topics4 = Topic.where('LOWER("link") like ?', '%' + search).where('metacode_id = ? AND user_id = ?', filterByMetacode.id, user).order('"name"') + @topics = @topics + (@topics2 - @topics) + @topics = @topics + (@topics3 - @topics) + @topics = @topics + (@topics4 - @topics) + end end elsif desc @@ -88,11 +102,23 @@ class MainController < ApplicationController @topics = Topic.where('LOWER("link") like ?', search).where('user_id = ?', user).order('"name"') end else #regular case, just search the name - search = '%' + term.downcase + '%' + search = term.downcase + '%' if !user @topics = Topic.where('LOWER("name") like ?', search).order('"name"') + @topics2 = Topic.where('LOWER("name") like ?', '%' + search).order('"name"') + @topics3 = Topic.where('LOWER("desc") like ?', '%' + search).order('"name"') + @topics4 = Topic.where('LOWER("link") like ?', '%' + search).order('"name"') + @topics = @topics + (@topics2 - @topics) + @topics = @topics + (@topics3 - @topics) + @topics = @topics + (@topics4 - @topics) elsif user @topics = Topic.where('LOWER("name") like ?', search).where('user_id = ?', user).order('"name"') + @topics2 = Topic.where('LOWER("name") like ?', '%' + search).where('user_id = ?', user).order('"name"') + @topics3 = Topic.where('LOWER("desc") like ?', '%' + search).where('user_id = ?', user).order('"name"') + @topics4 = Topic.where('LOWER("link") like ?', '%' + search).where('user_id = ?', user).order('"name"') + @topics = @topics + (@topics2 - @topics) + @topics = @topics + (@topics3 - @topics) + @topics = @topics + (@topics4 - @topics) end end else