I am working on a webpage linked to my database that has a search feature as the main function. Users have to search for Company's name to check which group the company belongs to etc. However, I need a fuzzy search logic to do company name screening. I tried many methods but the challenge is the company names are long. I used WHERE NAME LIKE %keywordfromform%
but its not fuzzy enough.
For example:
Actual: ABC Company 123 ROAD
User search: Road 123 ABC Company
The result should appear but it doesn't show, this leads to inaccuracy in searches.
actual : "ABC Company 123 ROAD"
user = "Road 123 ABC Company" use explode
or preg_split
for splitting the string into an array. As you don't know the order so it would be better to break the query string and search by word instead of searching for a whole string.
If you need any
of the words
SELECT * FROM table
WHERE column LIKE '%word1%'
OR column1 LIKE '%word2%'
OR column1 LIKE '%word3%'
If you need all
of the words to be present
SELECT * FROM table
WHERE column LIKE '%word1%'
AND column1 LIKE '%word2%'
AND column1 LIKE '%word3%'