Created
August 2, 2011 21:19
-
-
Save vanstee/1121250 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def self.build_fuzzy_query(name, options = {}) | |
[].tap do |q| | |
subq = [].tap do |subq| | |
Normalizer.short_name(name).split.uniq.each do |token| | |
subq << "short_name_text:#{token}^5" # exact match | |
subq << "short_name_text:#{token}~^3" # fuzzy match | |
subq << "marketing_alias_text:#{token}^5" # exact match | |
subq << "marketing_alias_text:#{token}~^3" # fuzzy match | |
end | |
# Acronyms | |
subq << "full_acronym_text:#{Normalizer.normalize(name)}" | |
subq << "short_acronym_text:#{Normalizer.normalize(name)}" | |
end | |
q << "first_letter_text:#{name[0, 1].downcase} AND ( #{subq.join(" OR ")} )" | |
# Domain | |
if options[:domain].present? | |
[:worldhq_domain_untokenized_text, :hq_domain_untokenized_text, :domain_untokenized_text].each do |field| | |
domain_normalized = options[:domain].gsub(/\s+/, '') | |
q << "#{field}:#{domain_normalized}^3" | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment