about summary refs log tree commit diff
path: root/app/helpers/search_helper.rb
blob: 100fdddb978381b36243f6bcb05c8b841cea6f57 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
require 'sixarm_ruby_unaccent'

module SearchHelper
	def expand_search_query(query)
    return '' if query.blank?
    query = query.strip.downcase.unaccent

    if query.include?(':')
      query_parts = query.split(':', 2)
      if query_parts[0] == 'tags'
        query = "^tags .*(#{query_parts[1].split.join('|')})"
      elsif query_parts[0].in?(%w(subj text desc))
        query = "^#{query_parts[0]} .*#{query_parts[1]}"
      end
    end

    query.gsub(/"(.*)"/, '\\y\1\\y')
  end
end