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)
This commit is contained in:
parent
7cff0fb6fe
commit
f721441f11
1 changed files with 28 additions and 2 deletions
|
@ -65,12 +65,26 @@ class MainController < ApplicationController
|
||||||
if term == ""
|
if term == ""
|
||||||
@topics = []
|
@topics = []
|
||||||
else
|
else
|
||||||
search = '%' + term.downcase + '%'
|
search = term.downcase + '%'
|
||||||
|
|
||||||
if !user
|
if !user
|
||||||
@topics = Topic.where('LOWER("name") like ?', search).where('metacode_id = ?', filterByMetacode.id).order('"name"')
|
@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
|
elsif user
|
||||||
@topics = Topic.where('LOWER("name") like ?', search).where('metacode_id = ? AND user_id = ?', filterByMetacode.id, user).order('"name"')
|
@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
|
||||||
end
|
end
|
||||||
elsif desc
|
elsif desc
|
||||||
|
@ -88,11 +102,23 @@ class MainController < ApplicationController
|
||||||
@topics = Topic.where('LOWER("link") like ?', search).where('user_id = ?', user).order('"name"')
|
@topics = Topic.where('LOWER("link") like ?', search).where('user_id = ?', user).order('"name"')
|
||||||
end
|
end
|
||||||
else #regular case, just search the name
|
else #regular case, just search the name
|
||||||
search = '%' + term.downcase + '%'
|
search = term.downcase + '%'
|
||||||
if !user
|
if !user
|
||||||
@topics = Topic.where('LOWER("name") like ?', search).order('"name"')
|
@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
|
elsif user
|
||||||
@topics = Topic.where('LOWER("name") like ?', search).where('user_id = ?', user).order('"name"')
|
@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
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
|
|
Loading…
Reference in a new issue