CodepadME / laravel-tricks

The source code for the Laravel Tricks website
http://laravel-tricks.com
MIT License
966 stars 298 forks source link

Fix the search bug #85

Closed yhbyun closed 8 years ago

yhbyun commented 9 years ago

If I search the tricks by test term, the following SQL is executed.

select count(*) as aggregate from `tricks` where `title` LIKE '%test%' or `description` LIKE '%test%' or
 (select count(*) from `tags` inner join `tag_trick` on `tags`.`id` = `tag_trick`.`tag_id` 
  where `tag_trick`.`trick_id` = `tricks`.`id` and `name` LIKE '%test%' or `slug` LIKE '%test%') >= 1 or 
 (select count(*) from `categories` inner join `category_trick` on `categories`.`id` = `category_trick`.`category_id` 
  where `category_trick`.`trick_id` = `tricks`.`id` and `name` LIKE '%test%' or `slug` LIKE '%test%') >= 1

Two parts of that SQL causes irrelevant result to the search term.

and `name` LIKE '%test%' or `slug` LIKE '%test%'
.
.
.
and `name` LIKE '%test%' or `slug` LIKE '%test%

I think that title only would be sufficient for search and in order to fix the above bug, I modified the code.

msurguy commented 8 years ago

@yhbyun thanks for the PR! Is there an example on the website where it would return an incorrect result set? Thanks very much for trying to explain the issue!

yhbyun commented 8 years ago

@msurguy http://laravel-tricks.com/search?q=eloquent

When I search with 'eloquent', many irrelevant result are returned, such as

msurguy commented 8 years ago

Thanks! I've merged the PR and will try to update the site soon!