Merge pull request #303 from Connoropolous/Robs-1st-edits

Robs 1st edits
This commit is contained in:
Connoropolous 2014-02-20 11:08:09 -08:00
commit 144069f82a

View file

@ -62,17 +62,29 @@ class MainController < ApplicationController
end end
if filterByMetacode if filterByMetacode
# !connor : Shouldn't this be checked for all cases, not just metacodes?
if term == "" if term == ""
@topics = [] @topics = []
else else
# !connor add % to the frontof this one too? why not?
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
@ -90,12 +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
# !connor : Definitely add the % out front here.
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
@ -113,7 +136,6 @@ class MainController < ApplicationController
@current = current_user @current = current_user
term = params[:term] term = params[:term]
#!connor is nil the same as false? why is it done different here?
user = params[:user] ? params[:user] : nil user = params[:user] ? params[:user] : nil
if term && !term.empty? && term.downcase[0..5] != "topic:" && term.downcase[0..6] != "mapper:" && term.downcase != "map:" if term && !term.empty? && term.downcase[0..5] != "topic:" && term.downcase[0..6] != "mapper:" && term.downcase != "map:"
@ -127,8 +149,7 @@ class MainController < ApplicationController
term = term[5..-1] term = term[5..-1]
desc = true desc = true
end end
# !connor make the search always '%' : term.downcase + '%' search = '%' + term.downcase + '%'
search = desc ? '%' + term.downcase + '%' : term.downcase + '%'
query = desc ? 'LOWER("desc") like ?' : 'LOWER("name") like ?' query = desc ? 'LOWER("desc") like ?' : 'LOWER("name") like ?'
if !user if !user
# !connor why is the limit 5 done here and not above? also, why not limit after sorting alphabetically? # !connor why is the limit 5 done here and not above? also, why not limit after sorting alphabetically?
@ -155,7 +176,6 @@ class MainController < ApplicationController
#remove "mapper:" if appended at beginning #remove "mapper:" if appended at beginning
term = term[7..-1] if term.downcase[0..6] == "mapper:" term = term[7..-1] if term.downcase[0..6] == "mapper:"
# !connor same question as above
@mappers = User.where('LOWER("name") like ?', term.downcase + '%').limit(5).order('"name"') @mappers = User.where('LOWER("name") like ?', term.downcase + '%').limit(5).order('"name"')
else else
@mappers = [] @mappers = []
@ -174,8 +194,7 @@ class MainController < ApplicationController
if term && !term.empty? if term && !term.empty?
@synapses = Synapse.select('DISTINCT "desc"'). @synapses = Synapse.select('DISTINCT "desc"').
# !connor this should likely also have the preceeding % where('LOWER("desc") like ?', '%' + term.downcase + '%').limit(5).order('"desc"')
where('LOWER("desc") like ?', term.downcase + '%').limit(5).order('"desc"')
render json: autocomplete_synapse_generic_json(@synapses) render json: autocomplete_synapse_generic_json(@synapses)