To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.

Statistics Download as Zip
| Branch: | Tag: | Revision:

root / vendor / plugins / redmine_tags / lib / redmine_project_filtering.rb @ 746:2ced57750157

History | View | Annotate | Download (551 Bytes)

1
module RedmineProjectFiltering
2

    
3
  # transforms a question and a list of custom fields into something that Project.search can process
4
  def self.calculate_tokens(question, custom_fields=nil)
5
    list = []
6
    list << custom_fields.values if custom_fields.present?
7
    list << question if question.present?
8

    
9
    tokens = list.join(' ').scan(%r{((\s|^)"[\s\w]+"(\s|$)|\S+)})
10
    tokens = tokens.collect{ |m| m.first.gsub(%r{(^\s*"\s*|\s*"\s*$)}, '') }
11
    
12
    # tokens must be at least 2 characters long
13
    tokens.select {|w| w.length > 1 }
14
  end
15

    
16
end