From 7c28e20b00b348bf9b4ae1fd56de83688f27c7b4 Mon Sep 17 00:00:00 2001 From: Robert Best Date: Thu, 13 Feb 2014 22:22:01 -0500 Subject: [PATCH] Update main_controller.rb I commented notifications to you connor with !connor.... I havent looked at how to sort better yet, but my markups should make the pre-sort results a little better --- app/controllers/main_controller.rb | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/app/controllers/main_controller.rb b/app/controllers/main_controller.rb index 3d936453..5cedd78c 100644 --- a/app/controllers/main_controller.rb +++ b/app/controllers/main_controller.rb @@ -62,9 +62,11 @@ class MainController < ApplicationController end if filterByMetacode + # !connor : Shouldn't this be checked for all cases, not just metacodes? if term == "" @topics = [] else + # !connor add % to the frontof this one too? why not? search = term.downcase + '%' if !user @@ -92,6 +94,7 @@ class MainController < ApplicationController @topics = Topic.where('LOWER("link") like ?', search).where('user_id = ?', user).order('"name"') end else #regular case, just search the name + # !connor : Definitely add the % out front here. search = term.downcase + '%' if !user @topics = Topic.where('LOWER("name") like ?', search).order('"name"') @@ -114,6 +117,7 @@ class MainController < ApplicationController @current = current_user term = params[:term] + #!connor is nil the same as false? why is it done different here? user = params[:user] ? params[:user] : nil if term && !term.empty? && term.downcase[0..5] != "topic:" && term.downcase[0..6] != "mapper:" && term.downcase != "map:" @@ -127,10 +131,11 @@ class MainController < ApplicationController term = term[5..-1] desc = true end - + # !connor make the search always '%' : term.downcase + '%' search = desc ? '%' + term.downcase + '%' : term.downcase + '%' query = desc ? 'LOWER("desc") like ?' : 'LOWER("name") like ?' if !user + # !connor why is the limit 5 done here and not above? also, why not limit after sorting alphabetically? @maps = Map.where(query, search).limit(5).order('"name"') elsif user @maps = Map.where(query, search).where('user_id = ?', user).limit(5).order('"name"') @@ -154,7 +159,7 @@ class MainController < ApplicationController #remove "mapper:" if appended at beginning 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"') else @mappers = [] @@ -173,6 +178,7 @@ class MainController < ApplicationController if term && !term.empty? @synapses = Synapse.select('DISTINCT "desc"'). + #!connor this should likely also have the preceeding % where('LOWER("desc") like ?', term.downcase + '%').limit(5).order('"desc"') render json: autocomplete_synapse_generic_json(@synapses)