3

My search allows users to search games in my database. The only problem is that if a user types multiple terms within the search, it will only get hits if those multiple words are right next to each other.

Example:

searched term = Call Duty Modern

result = none

BUT if they input:

searched term = Call of Duty -or- Modern Warfare

result = Call of Duty Modern Warfare 1/2/3 etc.

here is my mysql query:

$query = "SELECT ID, title FROM games WHERE title LIKE '%{$title}%' AND platform = :platform LIMIT $startFrom,15";
        $statement = $dbG->prepare($query);
        $statement->bindValue(':platform', $platform);
        $statement->execute();
        $gamesLike = $statement->fetch(PDO::FETCH_ASSOC);

I know i should break up each word and search each term but im afraid it would eat up all my programs speed...

are there any specific MYSQL query tweaks i can use to achieve the result i need?

Any suggestions would be greatly appreciated

Thank you for your time

1 Answer 1

6

full text searching is great for this: http://dev.mysql.com/doc/refman/5.0/en/fulltext-search.html

It essentially turns mysql into a search engine where you use match and against to get a rank back of how often the search terms show up in the column you are matching against. It can handle partial matches, multiple matches, excludes words that are small/common to help performance and allows for search keywords/symbols like +some -search will return results that must have some but can't have search.

Also it is surprisingly easy to setup as pretty much everything you need works by default.

Sign up to request clarification or add additional context in comments.

1 Comment

Wow, that is exactly what i needed (and was hoping mysql had) =)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.