-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from david-days/search_resource
Convert existed search function to resource-based search
- Loading branch information
Showing
64 changed files
with
1,010 additions
and
163 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
class QuestionsController < ApplicationController | ||
|
||
def index | ||
@title = "Recent Questions" | ||
@notes = DrupalNode.where(status: 1, type: 'note') | ||
.joins(:drupal_tag) | ||
.where('term_data.name LIKE ?', 'question:%') | ||
.order('node.nid DESC') | ||
.paginate(:page => params[:page], :per_page => 30) | ||
@wikis = DrupalNode.limit(10) | ||
.where(type: 'page', status: 1) | ||
.order("nid DESC") | ||
end | ||
|
||
def show | ||
if params[:author] && params[:date] | ||
@node = DrupalNode.where(path: "/notes/#{params[:author]}/#{params[:date]}/#{params[:id]}").first | ||
@node = @node || DrupalNode.where(path: "/report/#{params[:id]}").first | ||
else | ||
@node = DrupalNode.find params[:id] | ||
end | ||
|
||
unless @node.has_power_tag('question') | ||
flash[:error] = "Not a question" | ||
redirect_to "/" | ||
end | ||
|
||
if @node.author.status == 0 && !(current_user && (current_user.role == "admin" || current_user.role == "moderator")) | ||
flash[:error] = "The author of that note has been banned." | ||
redirect_to "/" | ||
elsif @node.status == 4 && (current_user && (current_user.role == "admin" || current_user.role == "moderator")) | ||
flash[:warning] = "First-time poster <a href='#{@node.author.name}'>#{@node.author.name}</a> submitted this #{time_ago_in_words(@node.created_at)} ago and it has not yet been approved by a moderator. <a class='btn btn-default btn-sm' href='/moderate/publish/#{@node.id}'>Approve</a> <a class='btn btn-default btn-sm' href='/moderate/spam/#{@node.id}'>Spam</a>" | ||
elsif @node.status == 4 && (current_user && current_user.id == @node.author.id) && !flash[:first_time_post] | ||
flash[:warning] = "Thank you for contributing open research, and thanks for your patience while your post is approved by <a href='/wiki/moderation'>community moderators</a> and we'll email you when it is published. In the meantime, if you have more to contribute, feel free to do so." | ||
elsif @node.status != 1 && !(current_user && (current_user.role == "admin" || current_user.role == "moderator")) | ||
# if it's spam or a draft | ||
# no notification; don't let people easily fish for existing draft titles; we should try to 404 it | ||
redirect_to "/" | ||
end | ||
|
||
@node.view | ||
@title = @node.latest.title | ||
@tags = @node.tags | ||
@tagnames = @tags.collect(&:name) | ||
|
||
set_sidebar :tags, @tagnames | ||
end | ||
|
||
def shortlink | ||
@node = DrupalNode.find params[:id] | ||
redirect_to @node.path(:question) | ||
end | ||
|
||
def popular | ||
@title = "Popular Questions" | ||
@notes = DrupalNode.where(status: 1, type: 'note') | ||
.joins(:drupal_tag) | ||
.where('term_data.name LIKE ?', 'question:%') | ||
.order('node_counter.totalcount DESC') | ||
.includes(:drupal_node_counter) | ||
.limit(20) | ||
@wikis = DrupalNode.limit(10) | ||
.where(type: 'page', status: 1) | ||
.order("nid DESC") | ||
@unpaginated = true | ||
render :template => 'questions/index' | ||
end | ||
|
||
def liked | ||
@title = "Highly liked Questions" | ||
@notes = DrupalNode.where(status: 1, type: 'note') | ||
.joins(:drupal_tag) | ||
.where('term_data.name LIKE ?', 'question:%') | ||
.order("cached_likes DESC") | ||
.limit(20) | ||
@wikis = DrupalNode.limit(10) | ||
.where(type: 'page', status: 1) | ||
.order("nid DESC") | ||
@unpaginated = true | ||
render :template => 'questions/index' | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
class SearchesController < ApplicationController | ||
|
||
before_filter :set_search_service | ||
|
||
def index | ||
end | ||
|
||
def new | ||
# Rendering advanced search form | ||
@title = 'Advanced search' | ||
@search = Search.new | ||
@nodes = [] | ||
end | ||
|
||
def create | ||
@title = 'Advanced search' | ||
@search = Search.new(key_words: params[:id], title: @title) | ||
|
||
if @search.save | ||
@nodes = @search.advanced_search(params[:id], params) | ||
render :show | ||
else | ||
puts 'search failed !' | ||
end | ||
end | ||
|
||
def show | ||
set_sidebar :tags, [params[:id]] | ||
end | ||
|
||
def normal_search | ||
@title = "Search" | ||
@tagnames = params[:id].split(',') | ||
@users = @search_service.users(params[:id]) | ||
set_sidebar :tags, [params[:id]] | ||
|
||
@notes = DrupalNode.paginate(page: params[:page]) | ||
.order("node.nid DESC") | ||
.where('(type = "note" OR type = "page" OR type = "map") AND node.status = 1 AND (node.title LIKE ? OR node_revisions.title LIKE ? OR node_revisions.body LIKE ?)', "%"+params[:id]+"%","%"+params[:id]+"%","%"+params[:id]+"%") | ||
.includes(:drupal_node_revision) | ||
end | ||
|
||
# def advanced | ||
# @title = "Advanced search" | ||
# all = !params[:notes] && !params[:wikis] && !params[:maps] && !params[:comments] | ||
# @nodes = [] | ||
# end | ||
|
||
# utility response to fill out search autocomplete | ||
# needs *dramatic* optimization | ||
|
||
def typeahead | ||
@match = @search_service.type_ahead(params[:id]) | ||
render json: @match | ||
end | ||
|
||
def questions | ||
@title = "Search questions" | ||
@tagnames = params[:id].split(',') | ||
@users = @search_service.users(params[:id]) | ||
set_sidebar :tags, [params[:id]] | ||
@notes = DrupalNode.where('type = "note" AND node.status = 1 AND title LIKE ?', "%" + params[:id] + "%") | ||
.joins(:drupal_tag) | ||
.where('term_data.name LIKE ?', 'question:%') | ||
.order('node.nid DESC') | ||
.page(params[:page]) | ||
if @notes.empty? | ||
session[:title] = params[:id] | ||
redirect_to '/post?tags=question:question&template=question&title='+params[:id]+'&redirect=question' | ||
else | ||
render :template => 'search/index' | ||
end | ||
end | ||
|
||
def questions_typeahead | ||
matches = [] | ||
questions = DrupalNode.where('type = "note" AND node.status = 1 AND title LIKE ?', "%" + params[:id] + "%") | ||
.joins(:drupal_tag) | ||
.where('term_data.name LIKE ?', 'question:%') | ||
.order('node.nid DESC') | ||
.limit(25) | ||
questions.each do |match| | ||
matches << "<i data-url='"+match.path(:question)+"' class='fa fa-question-circle'></i> "+match.title | ||
end | ||
render :json => matches | ||
end | ||
|
||
def map | ||
@users = DrupalUsers.where("lat != 0.0 AND lon != 0.0") | ||
end | ||
|
||
private | ||
def set_search_service | ||
@search_service = SearchService.new | ||
end | ||
|
||
def search_params | ||
params.require(:search).permit(:comments, :maps, :wikis, :@notes) | ||
end | ||
|
||
end |
Oops, something went wrong.