Reputation: 39
I have a search form and I would like to select similar items from database based on the searched title.
Now I use SELECT * FROM movies WHERE title LIKE '%".$_SESSION['search']."%';
But e.g. someone search for 'Jurassic Park2' or 'Jurasic Park 2' it doesn't give 'Jurassic Park 2'.
How can I select those movies which has some character difference against the searced title?
Upvotes: 3
Views: 1145
Reputation: 39
I tried the full text search:
SELECT * FROM movies WHERE MATCH(title) AGAINST('%".$_SESSION['search']."%' IN NATURAL LANGUAGE MODE) > 1 ORDER BY title;
I tried to rewrite the 1 to 0.5 or other smaller than 1, but was the same result. It gives the result if it totally contains the searched title.
Jurassic gives Jurassic World
but Jurasic gives nothing
Upvotes: 0
Reputation:
You're looking for Mysql full text search. Here's a tutorial to get started.
Basically you need to create a fulltext index on the field(s) you want to search, then you can use a query to look up similar values:
MATCH (col1,col2,...) AGAINST (expr [search_modifier])
Upvotes: 2
Reputation: 8616
Could have a look at using soundex, just note the stated limitations and I am not sure on it's performance on a large data set.
https://dev.mysql.com/doc/refman/5.7/en/string-functions.html#function_soundex
Upvotes: 0