Skip to content

Commit

Permalink
Merge pull request #12 from christianlupus/dev/fuzzy_search
Browse files Browse the repository at this point in the history
Added code for fuzzy searching
  • Loading branch information
Jeppe Zapp authored Jul 12, 2019
2 parents e718666 + 9cb5e7e commit 5bbf6a5
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions lib/Db/RecipeDb.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,15 @@ public function findRecipes($keywords) {

$qb->select(['r.recipe_id', 'r.name'])
->from('cookbook_keywords', 'k')
->where('k.name = \'' . $keywords[0] . '\'');
->where('LOWER(k.name) LIKE \'%' . strtolower($keywords[0]) . '%\'');

for($i = 1; $i < sizeof($keywords); $i++) {
$qb->orWhere('k.name = \'' . $keywords[$i] . '\'');
$qb->orWhere('LOWER(k.name) LIKE \'%' . strtolower($keywords[$i]) . '%\'');
}

foreach($keywords as $keyword) {
$lowerKW = strtolower($keyword);
$qb->orWhere("LOWER(r.name) LIKE '%$lowerKW%'");
}

$qb->join('k', 'cookbook_recipes', 'r', 'k.recipe_id = r.recipe_id');
Expand Down

0 comments on commit 5bbf6a5

Please sign in to comment.