Project

General



Profile

« Previous | Next » 

Revision 935

Search engine: search can be restricted to an exact phrase by using quotation marks (eg. hello "bye bye" can be used to search for "hello" and "bye bye" strings).

View differences:

trunk/app/controllers/search_controller.rb
52 52
      @object_types = @scope = %w(projects)
53 53
    end
54 54
    
55
    # extract tokens from the question
56
    # eg. hello "bye bye" => ["hello", "bye bye"]
57
    @tokens = @question.scan(%r{((\s|^)"[\s\w]+"(\s|$)|\S+)}).collect {|m| m.first.gsub(%r{(^\s*"\s*|\s*"\s*$)}, '')}
55 58
    # tokens must be at least 3 character long
56
    @tokens = @question.split.uniq.select {|w| w.length > 2 }
59
    @tokens = @tokens.uniq.select {|w| w.length > 2 }
57 60
    
58 61
    if !@tokens.empty?
59 62
      # no more than 5 tokens to search for
......
93 96
        # if only one project is found, user is redirected to its overview
94 97
        redirect_to :controller => 'projects', :action => 'show', :id => @results.first and return if @results.size == 1
95 98
      end
96
      @question = @tokens.join(" ")
97 99
    else
98 100
      @question = ""
99 101
    end

Also available in: Unified diff