Possible Enhancement method - City.where(name: approximates("york"))

33 views
Skip to first unread message

Leonardo Luarte

unread,
Jul 8, 2016, 7:27:08 PM7/8/16
to Ruby on Rails: Core
There are several times where we are looking for approximate strings, like parte of an email o a name. 
We are not sure if the mail is correctly written or if a name is using correct capitalization, so we usually go with

City.where("name ilike ?", "%york%")


Would it be better to have something like

City.where(name: approximates("york"))


Is this kind of change aesthetic or not? For me it would be quite comfortable, but its not that big of a change.

This could be used while checking for information in a Rails Console or event a search method.

It would also be great to have an even short approximation method, like so

City.where.approx(name: "francisco")


or 

City.where.approx(population: 1000000)


The interpretation of the approximates with numbers would be quite difficult to agree upon, but I'm sure it could be of great help, maybe something like this could work

City.where.approx(population: 1000000, radius: 0.1)


So that goes around ± 10% of the given value, but that would interefere with an attribute called radius...well..



Andrew Kaspick

unread,
Jul 8, 2016, 9:07:00 PM7/8/16
to Ruby on Rails: Core
Text search is a complex topic and is covered well by many existing gems.  I don't believe this should be in Rails core personally.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-co...@googlegroups.com.
To post to this group, send email to rubyonra...@googlegroups.com.
Visit this group at https://groups.google.com/group/rubyonrails-core.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages