Skip to content
Snippets Groups Projects
Commit 64aac738 authored by Mateus Rambo Strey's avatar Mateus Rambo Strey
Browse files

fix search order by name

parent 4f499d01
No related branches found
No related tags found
No related merge requests found
......@@ -16,7 +16,7 @@ class SearchController < ApplicationController
end
unless params[:qry].empty?
objectsFound = search(params[:qry])
objectsFound = search params[:qry], params[:sort]
@numFound = objectsFound.length
# if params[:sort]
......@@ -45,8 +45,6 @@ class SearchController < ApplicationController
#
# a = rater.sortByRate(items) # Returns sorted array of items
# objectsFound = a.collect{ |x| x.info } #get only the info fields(objects)
# when "title"
# objectsFound = sort_title(objectsFound);
# end
end
......@@ -70,11 +68,4 @@ class SearchController < ApplicationController
# items.each{ |item| item['author'] = sort_author(item['author']) if (item['author'].nil? ? [] : item['author']).size > 0 }
items
end
def sort_title(items)
# items = items.sort_by{|item| [ item['title'].to_s.downcase ]}
# items.each{ |item| item['title'] = sort_title(item['title']) if (item['title'].nil? ? [] : item['title']).size > 0 }
items
end
end
......@@ -97,17 +97,26 @@ module OrientDb
# ON LearningObject (name, description)
# FULLTEXT ENGINE LUCENE
# METADATA {"analyzer":"org.apache.lucene.analysis.br.BrazilianAnalyzer"}
def search(qry)
# learning_objects_hash = connection.query "
# SELECT EXPAND(rid)
# FROM index:learningobject_search
# WHERE key LUCENE '#{qry}'
# ", limit: 10000
learning_objects_hash = connection.query "SELECT @rid.asString(), last_modified FROM (
SELECT EXPAND(rid) FROM index:learningobject_search
WHERE key LUCENE '#{qry}'
)", limit: 10000
def search(qry, order = nil)
# TODO: fix search metadata from dspace
order = case order
when "author"
"metadata.key['dc.contributor.author']"
when "publicationasc"
"metadata.key['dc.date.submitted']"
when "publicationdesc"
"metadata.key['dc.date.submitted'] DESC"
when "title"
"name ASC"
else
nil
end
query = "SELECT EXPAND(rid) FROM index:learningobject_search WHERE key LUCENE '#{qry}'"
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|
......
module SearchEngine
module OrientdbLucene
def search(qry)
learning_object_repository.search(qry)
def search(qry, order = nil)
learning_object_repository.search(qry, order)
end
end
......
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