Skip to content

Instantly share code, notes, and snippets.

@rbeene
Last active December 12, 2015 00:38
Show Gist options
  • Save rbeene/4685122 to your computer and use it in GitHub Desktop.
Save rbeene/4685122 to your computer and use it in GitHub Desktop.
# sample query right before results are output
"#<Tire::Search::Search:0x007fe12432be20 @indices=[\"members\"], @types=[], @options={}, @path=\"/members/_search\", @query=#<Tire::Search::Query:0x007fe12432b358 @value={:bool=>{:must=>[{:term=>{:phone_number=>{:term=>\"555-555-1212\"}}}]}}, @boolean=#<Tire::Search::BooleanQuery:0x007fe12432b178 @options={}, @value={:must=>[{:term=>{:phone_number=>{:term=>\"555-555-1212\"}}}]}>>>"
mapping do
indexes :member_id, type: 'integer'
indexes :first_nm, boost: 20
indexes :last_nm, boost: 20
indexes :middle_nm, boost: 5
indexes :dob, type: 'date'
indexes :mailing_address
indexes :group_nm
indexes :user_nm, boost: 20
indexes :member_status
indexes :age_classification
indexes :member_classification_as_string
indexes :gender_as_string
indexes :gender_as_id, type: 'integer', boost: 50
indexes :email, boost: 100
indexes :phone_number, analyzer: "not_analyzed", boost: 100
indexes :zip_code
indexes :zip_code_as_id, type: 'integer', boost: 20
end
# search method
# phone number are pulled out of the params and collected based on regex
# they are then converted to match the 555-555-1212 format but results are still not found
phone_numbers = params[:query].scan(/(\d{3}\D{1}\d{3}\D{1}\d{4})/).flatten
formatted_phone_numbers = phone_numbers.collect{|phone| phone.gsub(/\.|-/, "")}
phone_numbers.each {|phone_number| query_string.delete(phone_number)} unless phone_numbers.blank?
phone_query = lambda do |q|
phone_number = PartyPhoneFax.convert_phone_number_string_for_display(formatted_phone_numbers.first)
q.must { term :phone_number, phone_number }
end
# results of mapping on members
{"members":{"member":{"properties":{"age_classification":{"type":"string"},"dob":{"type":"date","format":"dateOptionalTime"},"email":{"type":"string"},"first_nm":{"type":"string"},"gender":{"type":"string"},"gender_as_id":{"type":"long"},"group_nm":{"type":"string"},"id":{"type":"string"},"last_nm":{"type":"string"},"mailing_address":{"type":"string"},"member_classification":{"type":"string"},"member_id":{"type":"long"},"member_status":{"type":"string"},"phone_number":{"type":"string"},"type":{"type":"string"},"user_nm":{"type":"string"},"zip_code":{"type":"string"},"zip_code_as_id":{"type":"long"}}}}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment