Skip to content
Snippets Groups Projects
Commit d84ca25a authored by Israel Barreto Sant'Anna's avatar Israel Barreto Sant'Anna
Browse files

Fixed search query

parent 62c2663b
No related branches found
No related tags found
No related merge requests found
......@@ -11,6 +11,7 @@ class SearchService
# get results in cache or search
Rails.cache.fetch(cache_key, expires_in: 10.minutes) do
query = build_search_query params
p query
@connection.query query, limit: 10000
end
end
......@@ -28,9 +29,9 @@ class SearchService
end
def collection_query(params={})
qry = "SELECT *, created_at as published_at, out('BelongsTo')[0].name as author FROM Collection WHERE privacy = 'public' "
qry += "AND (name LUCENE '#{params[:query]}' OR description LUCENE '#{params[:query]}')" unless params[:query].blank?
qry_filter = params[:query].blank? ? " WHERE " : " AND "
qry = "SELECT *, created_at as published_at, out('BelongsTo')[0].name as author FROM Collection"
qry += " WHERE name LUCENE '#{params[:query]}' OR description LUCENE '#{params[:query]}'" unless params[:query].blank?
qry = "SELECT FROM (#{qry}) WHERE privacy = 'public'"
filter = collection_learning_objects_filter(params)
qry += " AND "+filter unless filter.blank?
qry
......@@ -39,15 +40,14 @@ class SearchService
def learning_object_query(params={})
qry = "SELECT FROM LearningObject"
qry +=" WHERE name LUCENE '#{params[:query]}' OR description LUCENE '#{params[:query]}' OR author LUCENE '#{params[:query]}'" unless params[:query].blank?
qry_filter = params[:query].blank? ? " WHERE " : " AND "
filter = learning_object_filters(params)
qry += qry_filter+filter unless filter.blank?
qry = "SELECT FROM (#{qry}) WHERE "+filter unless filter.blank?
qry
end
def collection_learning_objects_filter(params={})
qry = learning_object_filters(params)
qry = "learning_objects contains(#{qry})" unless qry.blank?
qry = "learning_objects CONTAINS (#{qry})" unless qry.blank?
qry
end
......@@ -60,7 +60,7 @@ class SearchService
end
qry += " AND ("+type_filter(params[:type])+")" unless params[:type].blank?
qry += " AND ("+year_filter(params[:year])+")" unless params[:year].blank?
qry[3..-1]
qry[5..-1]
end
def subject_filter(subjects)
......
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