I can think of convoluted and ugly ways to do this in mysql but i'm looking for a nice way. Let's say i have a bunch of school names, like
Meopham County Infant School
Speldhurst Nursery School
Rainbow Pre-School
The Annex School House
Fleet Learning Zone
Dartford Grammar School
Kiddliwinks
Hextable Kindergarten
The Rocking Horse Montessori Kinder
Little Angels Day Nursery
and i have a list of stopwords:
["school", "primary", "nursery", "college", "junior", "church", "cofe", "community", "infant"]
I have a ruby function "short_name" which returns the school name up to, but not including, the first instance of any of the stop words, so that we get
"Bower Grove School" => "Bower Grove"
"Fulston Manor School" => "Fulston Manor"
"St Johns Church Hall Play" => "St Johns"
"St Botolph's Church of England Voluntary Aided Primary School" => "St Botolph's"
"Fawkham House School" => "Fawkham House"
"Silverdale Day Nursery" => "Silverdale Day"
"Vigo Village School" => "Vigo Village"
"Sevenoaks Primary School" => "Sevenoaks"
"High Weald Academy" => "High Weald Academy"
"The Ebbsfleet Academy" => "The Ebbsfleet Academy"
That's all fine. My question is: what's the simplest way to do the above string processing in mysql?
eg, if i wanted to search by this short_name, i'd want to do something like
"select * from schools where <function(name)> = 'Bower Grove'"
what's the simplest way to do <function>
? I'd thought that some combination of substring(), and locate(), using a regex, would be the way to go, but it looks like i can't use a regex with locate.
I guess the regex would be
"school|primary|nursery|college|junior|church|cofe|community|infant"
thanks, Max