Reputation: 11206
I have a list of restaurants that I want to match with the restaurants in my database using phone number. The problem is that the numbers are formatted differently (i.e. (123)123-1234
or 123 123-123
or other combinations).
My current Solr search looks like this:
search = Restaurant.solr_search do
with(:phone, SunspotHelper.sanitize_term(pr.phone).gsub(/\s+/, ""))
paginate page: 1, per_page: 15
end
SunspotHelper.sanitize_term(pr.phone).gsub(/\s+/, "")
will strip down my search query to just numbers. However, the values in my database still contain other non-numeric characters and thus, search.hits
returns an empty array because I'm not getting any results.
Is there a way to strip my database values (:phone
) before Solr does a search?
Thanks.
Upvotes: 0
Views: 487
Reputation: 52799
Configure WordDelimiterFilterFactory for your phone number field.
This will allow you to index phone data in various format and make them searchable as well.
You would not need to do any change to the database.
Upvotes: 2