code tweaks to searchsynapses
This commit is contained in:
parent
b3b065e623
commit
d895bca1a4
1 changed files with 19 additions and 27 deletions
|
@ -68,25 +68,20 @@ class MainController < ApplicationController
|
||||||
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 = Set.new(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 = ?', filterByMetacode.id).order('"name"')
|
@topics2 = Set.new(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 = ?', filterByMetacode.id).order('"name"')
|
@topics3 = Set.new(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 = ?', filterByMetacode.id).order('"name"')
|
@topics4 = Set.new(Topic.where('LOWER("link") like ?', '%' + search).where('metacode_id = ? AND user_id = ?', filterByMetacode.id, user).order('"name"'))
|
||||||
@topics = @topics + (@topics2 - @topics)
|
else
|
||||||
@topics = @topics + (@topics3 - @topics)
|
@topics = Set.new(Topic.where('LOWER("name") like ?', search).where('metacode_id = ?', filterByMetacode.id).order('"name"'))
|
||||||
@topics = @topics + (@topics4 - @topics)
|
@topics2 = Set.new(Topic.where('LOWER("name") like ?', '%' + search).where('metacode_id = ?', filterByMetacode.id).order('"name"'))
|
||||||
|
@topics3 = Set.new(Topic.where('LOWER("desc") like ?', '%' + search).where('metacode_id = ?', filterByMetacode.id).order('"name"'))
|
||||||
elsif user
|
@topics4 = Set.new(Topic.where('LOWER("link") like ?', '%' + search).where('metacode_id = ?', filterByMetacode.id).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
|
||||||
|
|
||||||
|
#get unique elements only through the magic of Sets
|
||||||
|
@topics = (@topics + @topics2 + @topics3 + @topics4).to_a
|
||||||
end
|
end
|
||||||
elsif desc
|
elsif desc
|
||||||
search = '%' + term.downcase + '%'
|
search = '%' + term.downcase + '%'
|
||||||
|
@ -211,23 +206,20 @@ class MainController < ApplicationController
|
||||||
|
|
||||||
#limit to 5 results
|
#limit to 5 results
|
||||||
@synapses = @synapses.slice(0,5)
|
@synapses = @synapses.slice(0,5)
|
||||||
|
|
||||||
render json: autocomplete_synapse_generic_json(@synapses)
|
|
||||||
|
|
||||||
elsif topic1id && !topic1id.empty?
|
elsif topic1id && !topic1id.empty?
|
||||||
@one = Synapse.where('node1_id = ? AND node2_id = ?', topic1id, topic2id)
|
@one = Synapse.where('node1_id = ? AND node2_id = ?', topic1id, topic2id)
|
||||||
@two = Synapse.where('node2_id = ? AND node1_id = ?', topic1id, topic2id)
|
@two = Synapse.where('node2_id = ? AND node1_id = ?', topic1id, topic2id)
|
||||||
@synapses = @one + @two
|
@synapses = @one + @two
|
||||||
@synapses.sort! {|s1,s2| s1.desc <=> s2.desc }
|
@synapses.sort! {|s1,s2| s1.desc <=> s2.desc }.to_a
|
||||||
|
|
||||||
#read this next line as 'delete a synapse if its private and you're either 1. logged out or 2. logged in but not the synapse creator
|
#permissions
|
||||||
@synapses.to_a.delete_if {|s| s.permission == "private" && (!authenticated? || (authenticated? && @current.id != s.user_id)) }
|
@synapses.delete_if {|s| s.permission == "private" && !authenticated? }
|
||||||
|
@synapses.delete_if {|s| s.permission == "private" && authenticated? && @current.id != s.user_id }
|
||||||
render json: autocomplete_synapse_array_json(@synapses)
|
|
||||||
else
|
else
|
||||||
@synapses = []
|
@synapses = []
|
||||||
render json: autocomplete_synapse_array_json(@synapses)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
render json: utocomplete_synapse_array_json(@synapses)
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue