From 4d6c67391119239075589a51bb977017d29de686 Mon Sep 17 00:00:00 2001 From: Ujitha Perera Date: Fri, 3 Jun 2016 17:53:59 +0530 Subject: [PATCH 1/3] add jbuilder gem --- Gemfile | 1 + 1 file changed, 1 insertion(+) diff --git a/Gemfile b/Gemfile index 02008e5e4c..d722b56b4a 100644 --- a/Gemfile +++ b/Gemfile @@ -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' \ No newline at end of file From dafdfad4510eeffa72ac685a07b454172633a317 Mon Sep 17 00:00:00 2001 From: Ujitha Perera Date: Fri, 3 Jun 2016 18:00:58 +0530 Subject: [PATCH 2/3] fix conflicts --- app/controllers/search_controller.rb | 32 +-------------------- app/services/search_service.rb | 42 ++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 31 deletions(-) create mode 100644 app/services/search_service.rb diff --git a/app/controllers/search_controller.rb b/app/controllers/search_controller.rb index b9954fb47d..4413947662 100644 --- a/app/controllers/search_controller.rb +++ b/app/controllers/search_controller.rb @@ -39,37 +39,7 @@ def advanced # 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 << " "+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 << " "+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 << " "+match.title - end - DrupalUsers.limit(5) - .order("uid DESC") - .where('name LIKE ? AND access != 0', "%" + params[:id] + "%").each do |match| - matches << " "+match.name - end - DrupalTag.includes(:drupal_node) - .where('node.status = 1') - .limit(5) - .where('name LIKE ?', "%" + params[:id] + "%").each do |match| - matches << " "+match.name - end - render :json => matches + render json: SearchService.new.type_ahead(params[:id]) end def map diff --git a/app/services/search_service.rb b/app/services/search_service.rb new file mode 100644 index 0000000000..eeaf1397f1 --- /dev/null +++ b/app/services/search_service.rb @@ -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 << " "+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 << " "+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 << " "+match.title + end + DrupalUsers.limit(5) + .order("uid DESC") + .where('name LIKE ? AND access != 0', "%" + id + "%").each do |match| + matches << " "+match.name + end + DrupalTag.includes(:drupal_node) + .where('node.status = 1') + .limit(5) + .where('name LIKE ?', "%" + id + "%").each do |match| + matches << " "+match.name + end + return matches + end + + +end From 32c2ed0743ee46127d0137e12c40a1ebafc688f5 Mon Sep 17 00:00:00 2001 From: Ujitha Perera Date: Fri, 3 Jun 2016 18:22:46 +0530 Subject: [PATCH 3/3] add search index jbuilder --- app/controllers/search_controller.rb | 5 ++--- app/views/search/index.html.erb | 2 +- app/views/search/index.json.jbuider | 2 ++ 3 files changed, 5 insertions(+), 4 deletions(-) create mode 100644 app/views/search/index.json.jbuider diff --git a/app/controllers/search_controller.rb b/app/controllers/search_controller.rb index 4413947662..14d1521513 100644 --- a/app/controllers/search_controller.rb +++ b/app/controllers/search_controller.rb @@ -32,14 +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 - render json: SearchService.new.type_ahead(params[:id]) + @match = SearchService.new.type_ahead(params[:id]) + render json: @match end def map diff --git a/app/views/search/index.html.erb b/app/views/search/index.html.erb index d19912d8d9..a4c0d3cc2b 100644 --- a/app/views/search/index.html.erb +++ b/app/views/search/index.html.erb @@ -2,7 +2,7 @@
-

Search results for <%= params[:id] %> (advanced search)

+

Search results for <%= params[:id] %> (advanced search)

<% if @notes.length == 0 %> diff --git a/app/views/search/index.json.jbuider b/app/views/search/index.json.jbuider new file mode 100644 index 0000000000..33f14e62cd --- /dev/null +++ b/app/views/search/index.json.jbuider @@ -0,0 +1,2 @@ +json.users @users +json.notes @notes \ No newline at end of file