Skip to content

Commit

Permalink
Merge pull request #1 from david-days/to_service
Browse files Browse the repository at this point in the history
Foundation structure for searching feature
  • Loading branch information
david-days committed Jun 3, 2016
2 parents 0410186 + 32c2ed0 commit 9d902e4
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 34 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,4 @@ gem "rack-openid"
gem "authlogic", "3.2.0"
gem "php-serialize", :require => "php_serialize"
gem 'less-rails', '~> 2.6'
gem 'jbuilder'
35 changes: 2 additions & 33 deletions app/controllers/search_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,44 +32,13 @@ def advanced
.order("nid DESC")
.where('status = 1 AND comment LIKE ?', "%" + params[:id] + "%") if params[:comments] || all
end


end

# utility response to fill out search autocomplete
# needs *dramatic* optimization
def typeahead
matches = []
DrupalNode.limit(5)
.order("nid DESC")
.where('type = "note" AND node.status = 1 AND title LIKE ?', "%" + params[:id] + "%")
.select("title,type,nid,path").each do |match|
matches << "<i data-url='"+match.path+"' class='fa fa-file'></i> "+match.title
end
DrupalNode.limit(5)
.order("nid DESC")
.where('(type = "page" OR type = "place" OR type = "tool") AND node.status = 1 AND title LIKE ?', "%" + params[:id] + "%")
.select("title,type,nid,path").each do |match|
matches << "<i data-url='"+match.path+"' class='fa fa-"+match.icon+"'></i> "+match.title
end
DrupalNode.limit(5)
.order("nid DESC")
.where('type = "map" AND node.status = 1 AND title LIKE ?', "%" + params[:id] + "%")
.select("title,type,nid,path").each do |match|
matches << "<i data-url='"+match.path+"' class='fa fa-"+match.icon+"'></i> "+match.title
end
DrupalUsers.limit(5)
.order("uid DESC")
.where('name LIKE ? AND access != 0', "%" + params[:id] + "%").each do |match|
matches << "<i data-url='/profile/"+match.name+"' class='fa fa-user'></i> "+match.name
end
DrupalTag.includes(:drupal_node)
.where('node.status = 1')
.limit(5)
.where('name LIKE ?', "%" + params[:id] + "%").each do |match|
matches << "<i data-url='/tag/"+match.name+"' class='fa fa-tag'></i> "+match.name
end
render :json => matches
@match = SearchService.new.type_ahead(params[:id])
render json: @match
end

def map
Expand Down
42 changes: 42 additions & 0 deletions app/services/search_service.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
class SearchService

def initialize
end

def type_ahead(id)
matches = []

DrupalNode.limit(5)
.order("nid DESC")
.where('type = "note" AND node.status = 1 AND title LIKE ?', "%" + id + "%")
.select("title,type,nid,path").each do |match|
matches << "<i data-url='"+match.path+"' class='fa fa-file'></i> "+match.title
end
DrupalNode.limit(5)
.order("nid DESC")
.where('(type = "page" OR type = "place" OR type = "tool") AND node.status = 1 AND title LIKE ?', "%" + id + "%")
.select("title,type,nid,path").each do |match|
matches << "<i data-url='"+match.path+"' class='fa fa-"+match.icon+"'></i> "+match.title
end
DrupalNode.limit(5)
.order("nid DESC")
.where('type = "map" AND node.status = 1 AND title LIKE ?', "%" + id + "%")
.select("title,type,nid,path").each do |match|
matches << "<i data-url='"+match.path+"' class='fa fa-"+match.icon+"'></i> "+match.title
end
DrupalUsers.limit(5)
.order("uid DESC")
.where('name LIKE ? AND access != 0', "%" + id + "%").each do |match|
matches << "<i data-url='/profile/"+match.name+"' class='fa fa-user'></i> "+match.name
end
DrupalTag.includes(:drupal_node)
.where('node.status = 1')
.limit(5)
.where('name LIKE ?', "%" + id + "%").each do |match|
matches << "<i data-url='/tag/"+match.name+"' class='fa fa-tag'></i> "+match.name
end
return matches
end


end
2 changes: 1 addition & 1 deletion app/views/search/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<div class="col-md-9">

<h3>Search results for <i style="color:#aaa;"><%= params[:id] %></i> <small>(<a href="/search/advanced/<%= params[:id] %>">advanced search</a>)</h3>
<h3>Search results for <i style="color:#aaa;"><%= params[:id] %></i> <small>(<a href="/search/advanced/<%= params[:id] %>">advanced search</a>)</small></h3>

<% if @notes.length == 0 %>

Expand Down
2 changes: 2 additions & 0 deletions app/views/search/index.json.jbuider
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
json.users @users
json.notes @notes

0 comments on commit 9d902e4

Please sign in to comment.