diff --git a/app/controllers/search_controller.rb b/app/controllers/search_controller.rb index 7ba640079c6e661adddb6fc044de222bf98efb89..8798aceb0962910811d7ac70343c7f2ea9729280 100644 --- a/app/controllers/search_controller.rb +++ b/app/controllers/search_controller.rb @@ -38,26 +38,11 @@ class SearchController < ApplicationController # end end - # build objects from one page only - @objects = build_page_result(objectsFound, page, @pagination_limit) - @result = Kaminari.paginate_array(objectsFound).page(page).per(@pagination_limit) - render partial: 'search/fetch' - end - - private - - def build_page_result(objects, page, limit) - start = (page * limit) - limit - offset = page * limit - 1 - # build only objects from page - LearningObjectBuilder.build(objects[start..offset]) - end + # build objects from one page only + @objects = LearningObjectBuilder.build(@result) - def order_author(items) - # items = items.order_by{|item| [ item['author'].to_s.downcase ]} - # items.each{ |item| item['author'] = order_author(item['author']) if (item['author'].nil? ? [] : item['author']).size > 0 } - items + render partial: 'search/fetch' end end diff --git a/app/repositories/orient_db/learning_object_repository.rb b/app/repositories/orient_db/learning_object_repository.rb index d126c700966b8887d53a317d798a4e3e0908e19c..24f4f607010101f55a833860372dfedff2b74979 100644 --- a/app/repositories/orient_db/learning_object_repository.rb +++ b/app/repositories/orient_db/learning_object_repository.rb @@ -130,33 +130,48 @@ module OrientDb # FULLTEXT ENGINE LUCENE # METADATA {"analyzer":"org.apache.lucene.analysis.br.BrazilianAnalyzer"} def search(params) - # TODO: fix search metadata from dspace - order = params[:order] - qry = params[:query] - unless order.nil? - order = case order - when "author" - "author" - when "publicationasc" - "created_at" - when "publicationdesc" - "created_at DESC" - when "title" - "name ASC" + # mount cache_key with params + valid_params = %w(query order subject type school_year year) + cache_key = "search_result/" + valid_params.each do |param| + if params[param].class == Array + cache_key += params[param].join('-') else - nil + cache_key += params[param].to_s end + cache_key += '/' unless (param == valid_params.last) end - query = "SELECT EXPAND(rid) FROM index:learningobject_search WHERE key LUCENE '#{qry}'" - query = "SELECT * FROM (" + query + ") WHERE " + fetch_types(params[:type]) unless params[:type].blank? - query = "SELECT * FROM (" + query + ") ORDER BY #{order}" unless order.nil? - query = "SELECT @rid.asString(), last_modified FROM (" + query + ")" - learning_objects_hash = connection.query query, limit: 10000 + # get results in cache or search + Rails.cache.fetch(cache_key, expires_in: 10.minutes) do + qry = params[:query] + + order = params[:order] + unless order.nil? + order = case order + when "author" + "author" + when "publicationasc" + "created_at" + when "publicationdesc" + "created_at DESC" + when "title" + "name ASC" + else + nil + end + end + + query = "SELECT EXPAND(rid) FROM index:learningobject_search WHERE key LUCENE '#{qry}'" + query = "SELECT * FROM (" + query + ") WHERE " + fetch_types(params[:type]) unless params[:type].blank? + query = "SELECT * FROM (" + query + ") ORDER BY #{order}" unless order.nil? + query = "SELECT @rid.asString(), last_modified FROM (" + query + ")" + learning_objects_hash = connection.query query, limit: 10000 - # return only rids with their modification time - learning_objects_hash.map do |e| - {'@rid': e['rid'], 'last_modified': e['last_modified']} + # return only rids with their modification time + learning_objects_hash.map do |e| + {'@rid': e['rid'], 'last_modified': e['last_modified']} + end end end diff --git a/config/puma.rb b/config/puma.rb index 088d709485919f1e58adba90a35f00f05f3c17dc..9642a0d7ded117cf53d4aee0fae656b9bab7eb95 100644 --- a/config/puma.rb +++ b/config/puma.rb @@ -7,8 +7,6 @@ threads 1, 6 app_dir = File.expand_path("../..", __FILE__) shared_dir = "#{app_dir}/shared" -daemonize - # Default to production rails_env = ENV['RAILS_ENV'] || "production" environment rails_env diff --git a/portalmec.service b/portalmec.service index 60f49df81a3dc2be7378a0bc39cb9fc832ae7bfa..ed539a61d6c1a25e32427ced4775e225b33ae12c 100644 --- a/portalmec.service +++ b/portalmec.service @@ -3,10 +3,8 @@ Description=Control puma for portalmec After=nginx.service [Service] -Type=simple ExecStart=/portalmec/puma.sh start ExecStop=/portalmec/puma.sh stop -Restart=always [Install] WantedBy=multi-user.target diff --git a/puma.sh b/puma.sh index e02e69804ff83d007b73ce8225b02bcb5c6931b6..2baa709eed089d4c08061a55e8d642c616f7d587 100644 --- a/puma.sh +++ b/puma.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash source /home/.rvm/scripts/rvm export PUMA_APP_DIR=/portalmec