I am implementing a search function for a REST API and it is my first time dealing with large database searches.
My MySQL Location table has the following columns
| id | name | email | phone | postcode | address | verified |
A user can search for a Location by name, email, phone, postcode or address
.
The input search string does not separate the different fields, i.e. there is only one input textbox and that string gets matched with each of the searchable fields above (this is purposely wanted).
What i have been doing up until now is taking the input string and running a MATCH ... AGAINST query for each searchable column, merging the results and returning.
However, i wouldn't it be better to create a support indexed table (location_query
) that has two columns.
| location_id | match_query |
and when a Location is added i can add a new row to the location_query that has a value like
0 | {NAME} {EMAIL} {PHONE} {POSTCODE} {ADDRESS}
and then simply run a FULLTEXT search on the match_query column?
Could this work?