0

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.

Huy
  • 10,806
  • 13
  • 55
  • 99

1 Answers1

2

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.

Jayendra
  • 52,349
  • 4
  • 80
  • 90
  • Is there another solution to this problem? If I change the schema, I would have to reindex solr and that would take 1-2 days. – Huy Nov 01 '12 at 19:09
  • Even if you filter the data at client side you would need to reindex that data completely. So the better option is to handle it effectively at Solr side. – Jayendra Nov 02 '12 at 03:58