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

module SearchHelper
	def expand_search_query(query)
    return '' if query.blank?
    if query.include?(':')
      query_parts = query.split(':', 2)
      if query_parts[0].in?(%w(tags subj text desc))
        query = "^#{query_parts[0]} .*#{query_parts[1]}"
      end
    end
    query.downcase.unaccent.gsub(/"(.*)"/, '\\y\1\\y')
  end
end