fix the [more] link
[opensuse:software-o-o.git] / app / controllers / search_controller.rb
1 class SearchController < ApplicationController
2   layout "application"
3
4   def index
5     if params[:lang].nil?
6       lang = request.compatible_language_from(LANGUAGES) || "en"
7     else
8       lang = params[:lang][0]
9     end
10     @lang = lang
11     GetText.locale = lang
12
13     if params[:baseproject]
14       @baseproject = params[:baseproject]
15     end
16     if params[:q]
17       perform_search
18     end
19   end
20
21   def download
22      DownloadHistory.create :query => params[:query], :base => params[:base], 
23                             :file => params[:file]              
24      redirect_to "http://download.opensuse.org/repositories/" + params[:file]
25   end
26
27   private
28
29   def perform_search
30     @query = params[:q]
31     @baseproject = params[:baseproject]
32     @current_page = params[:p].to_i
33     @current_page = 1 if @current_page == 0
34
35     return false if @query.length < 2
36     return false if @query =~ / / and @query.split(" ").select{|e| e.length < 2 }.size > 0
37
38     base = @baseproject=="ALL" ? "" : @baseproject
39     @result = Seeker.prepare_result(CGI.escape(@query).gsub("+", " "), base)
40     if @current_page == 1 and @result.length > 1 # ignore sub pages
41       SearchHistory.create :query => @query, :base => @baseproject, :patterns => @result.pattern_count, 
42                            :binaries => @result.binary_count, :count => @result.length
43     end
44     return true
45   end
46 end