diff --git a/app/controllers/articles_controller.rb b/app/controllers/articles_controller.rb index 02593895..947576d9 100644 --- a/app/controllers/articles_controller.rb +++ b/app/controllers/articles_controller.rb @@ -1,7 +1,7 @@ class ArticlesController < ApplicationController + # GET /articles # GET /articles.json - def index @bodyclass = "results" diff --git a/app/controllers/categories_controller.rb b/app/controllers/categories_controller.rb index e89faea4..b0dd5114 100644 --- a/app/controllers/categories_controller.rb +++ b/app/controllers/categories_controller.rb @@ -1,6 +1,6 @@ class CategoriesController < ApplicationController def index - @bodyclass = "results" + @bodyclass = "results" @categories = Category.by_access_count respond_to do |format| @@ -8,18 +8,19 @@ def index format.json { render json: @categories } end end + def show - return render(:template => 'categories/missing') unless Category.exists? params[:id] + return render(:template => 'categories/missing') unless Category.exists? params[:id] @category = Category.find(params[:id]) # redirection of old permalinks - if request.path != category_path( @category ) + if request.path != category_path(@category) logger.info "Old permalink: #{request.path}" return redirect_to @category, status: :moved_permanently end @category.delay.increment! :access_count - + @content_html = BlueCloth.new(@category.name).to_html @bodyclass = "results" diff --git a/app/controllers/contacts_controller.rb b/app/controllers/contacts_controller.rb index a56504fc..8d1fd717 100644 --- a/app/controllers/contacts_controller.rb +++ b/app/controllers/contacts_controller.rb @@ -21,5 +21,4 @@ def show end end - end diff --git a/app/controllers/guides_controller.rb b/app/controllers/guides_controller.rb index 62dd6241..f78590b8 100644 --- a/app/controllers/guides_controller.rb +++ b/app/controllers/guides_controller.rb @@ -6,7 +6,7 @@ def show return render(:template => 'articles/missing') unless @article.published? #redirection of old permalinks - if request.path != guide_path( @article ) + if request.path != guide_path(@article) logger.info "Old permalink: #{request.path}" return redirect_to @article, status: :moved_permanently end @@ -24,7 +24,7 @@ def show render :show_html and return end - @content_main = @article.md_to_html( @article.content ) + @content_main = @article.md_to_html(@article.content) respond_to do |format| format.html # show.html.erb diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb index f670e72b..edf5884e 100644 --- a/app/controllers/home_controller.rb +++ b/app/controllers/home_controller.rb @@ -6,7 +6,7 @@ def index @popular_categories = Category.by_access_count.limit(3) end - def about - end + def about + end end diff --git a/app/controllers/quick_answers_controller.rb b/app/controllers/quick_answers_controller.rb index 1965ef9a..64b22552 100644 --- a/app/controllers/quick_answers_controller.rb +++ b/app/controllers/quick_answers_controller.rb @@ -2,18 +2,18 @@ class QuickAnswersController < ApplicationController def show return render(:template => 'articles/missing') unless QuickAnswer.exists? params[:id] - + @article = QuickAnswer.find(params[:id]) - + # refuse to display unpublished articles return render(:template => 'articles/missing') unless @article.published? #redirection of old permalinks - if request.path != quick_answer_path( @article ) + if request.path != quick_answer_path(@article) logger.info "Old permalink: #{request.path}" return redirect_to @article, :status => :moved_permanently end - + # basic statistics on how many times an article has been accessed @article.delay.increment! :access_count @article.delay.category.increment!(:access_count) if @article.category @@ -24,9 +24,9 @@ def show render :show_html and return end - @content_main = @article.md_to_html( :content_main ) - @content_main_extra = @article.md_to_html( :content_main_extra ) - @content_need_to_know = @article.md_to_html( :content_need_to_know ) + @content_main = @article.md_to_html(:content_main) + @content_main_extra = @article.md_to_html(:content_main_extra) + @content_need_to_know = @article.md_to_html(:content_need_to_know) respond_to do |format| format.html # show.html.erb diff --git a/app/controllers/search_controller.rb b/app/controllers/search_controller.rb index 5b0d41d7..0ccdce59 100644 --- a/app/controllers/search_controller.rb +++ b/app/controllers/search_controller.rb @@ -1,24 +1,33 @@ class SearchController < ApplicationController def index - query = params[:q].strip - return redirect_to root_path if params[:q].blank? + return redirect_to root_path if params[:q].blank? + query = params[:q].strip @query = query - # spell check the query. + + # spell check the query. @query_corrected = Article.spell_check query + # remove puntuation and plurals. query = query.downcase.gsub(/[^\w]/, ' ').gsub(/ . /, ' ') + # remove stop words query = Article.remove_stop_words query - # Searchify can't handle requests longer than this (because of query expansion + Tanker inefficencies. >10 can result in >8000 byte request strings) + + # Searchify can't handle requests longer than this (because of query + # expansion + Tanker inefficencies. >10 can result in >8000 byte request + # strings) if query.split.size > 10 || query.blank? @query_corrected = query @results = [] return end + # expand the query - query_final = Article.expand_query( query ) + query_final = Article.expand_query(query) + # perform the search @results = Article.search(query_final) + # Log the search results puts "search-request: IP:#{request.env['REMOTE_ADDR']}, params[:query]:#{query}, QUERY:#{query_final}, FIRST_RESULT:#{@results.first.title unless @results.empty?}, RESULTS_N:#{@results.size}" diff --git a/app/controllers/web_services_controller.rb b/app/controllers/web_services_controller.rb index 123d47f2..9b8159c6 100644 --- a/app/controllers/web_services_controller.rb +++ b/app/controllers/web_services_controller.rb @@ -1,15 +1,15 @@ class WebServicesController < ApplicationController - + def show return render(:template => 'articles/missing') unless WebService.exists? params[:id] - + @article = WebService.find(params[:id]) # refuse to display unpublished articles return render(:template => 'articles/missing') unless @article.published? #redirection of old permalinks - if request.path != web_service_path( @article ) + if request.path != web_service_path(@article) logger.info "Old permalink: #{request.path}" return redirect_to @article, status: :moved_permanently end @@ -24,16 +24,14 @@ def show render :show_html and return end - @content_main = @article.md_to_html( :content_main ) - @content_main_extra = @article.md_to_html( :content_main_extra ) - @content_need_to_know = @article.md_to_html( :content_need_to_know ) - + @content_main = @article.md_to_html(:content_main) + @content_main_extra = @article.md_to_html(:content_main_extra) + @content_need_to_know = @article.md_to_html(:content_need_to_know) respond_to do |format| format.html # show.html.erb format.json { render json: @article } - end - end + end + end - end