Skip to content

Instantly share code, notes, and snippets.

@rodrigodealer
Created October 17, 2010 13:30
Show Gist options
  • Save rodrigodealer/630854 to your computer and use it in GitHub Desktop.
Save rodrigodealer/630854 to your computer and use it in GitHub Desktop.
def localiza
page = params[:page]? params[:page].to_i : 1
per_page = params[:per_page]? params[:per_page].to_i : 10
fields = [:pergunta, :resposta, :sistema_nome]
if params[:questao].present?
sistema = params[:questao][:sistema_id]
nome_sistema = params[:questao][:sistema_nome]
query = params[:questao][:keywords]
tipo = params[:questao][:tipo]
tags = params[:questao][:tags]
fields = fields.select {|i| i if i == tipo.to_sym } unless
tipo.nil? || tipo == ''
end
resultados = Sunspot.search(Questao) do
keywords(query, :fields => fields) unless query.nil? || query == ''
with(:sistema, sistema) unless sistema.nil? || sistema == ''
with(:nome_sistema, nome_sistema) unless nome_sistema.nil? || nome_sistema == ''
with(:tag_nome, tags) unless tags.nil? || tags == ''
paginate(:page => page, :per_page => per_page)
order_by :nome_sistema, :asc
end
return resultados.results
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment