Skip to content

Commit

Permalink
bug symfony#735 Allow to search blog posts with unicode characters (j…
Browse files Browse the repository at this point in the history
…aviereguiluz)

This PR was merged into the master branch.

Discussion
----------

Allow to search blog posts with unicode characters

This fixes symfony#734.

The search engine is now more strict because it's case sensitive (if the post title is `Lorém ipsum`, `lorém` and `Lorem` gives no results; you must search for `Lorém`). I'd say it's OK because we're not building a real search engine. Thoughts?

Commits
-------

0e1c9d3 Allow to search blog posts with unicode characters
  • Loading branch information
javiereguiluz committed Dec 27, 2017
2 parents f4a7ac8 + 0e1c9d3 commit 6d692af
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Repository/PostRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,15 +94,15 @@ public function findBySearchQuery(string $rawQuery, int $limit = Post::NUM_ITEMS
*/
private function sanitizeSearchQuery(string $query): string
{
return preg_replace('/[^[:alnum:] ]/', '', trim(preg_replace('/[[:space:]]+/', ' ', $query)));
return trim(preg_replace('/[[:space:]]+/', ' ', $query));
}

/**
* Splits the search query into terms and removes the ones which are irrelevant.
*/
private function extractSearchTerms(string $searchQuery): array
{
$terms = array_unique(explode(' ', mb_strtolower($searchQuery)));
$terms = array_unique(explode(' ', $searchQuery));

return array_filter($terms, function ($term) {
return 2 <= mb_strlen($term);
Expand Down

0 comments on commit 6d692af

Please sign in to comment.