Skip to content
Snippets Groups Projects
Commit 211f2c29 authored by Mauricio Giacomini Girardello's avatar Mauricio Giacomini Girardello
Browse files

Merge branch 'master' of gitlab.c3sl.ufpr.br:portalmec/portalmec

parents 3468b84a b3cd1273
No related branches found
No related tags found
No related merge requests found
......@@ -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
......@@ -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
......
......@@ -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
......
......@@ -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
#!/bin/sh
#!/bin/bash
source /home/.rvm/scripts/rvm
export PUMA_APP_DIR=/portalmec
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment