Fix typos and check-in Escaper

This commit is contained in:
Mathieu Darse
2015-03-19 16:41:53 +01:00
parent b1a03ae566
commit 679106d226
3 changed files with 21 additions and 1 deletions

View File

@@ -77,7 +77,7 @@ class SearchEngineServiceProvider implements ServiceProviderInterface
}); });
$app['elasticsearch.facets_response.factory'] = $app->protect(function (array $response) use ($app) { $app['elasticsearch.facets_response.factory'] = $app->protect(function (array $response) use ($app) {
return new FacetsResponse(new Excaper(), $response); return new FacetsResponse(new Escaper(), $response);
}); });

View File

@@ -20,6 +20,7 @@ use Alchemy\Phrasea\SearchEngine\SearchEngineInterface;
use Alchemy\Phrasea\SearchEngine\SearchEngineOptions; use Alchemy\Phrasea\SearchEngine\SearchEngineOptions;
use Alchemy\Phrasea\SearchEngine\SearchEngineResult; use Alchemy\Phrasea\SearchEngine\SearchEngineResult;
use Alchemy\Phrasea\Exception\RuntimeException; use Alchemy\Phrasea\Exception\RuntimeException;
use Closure;
use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\ArrayCollection;
use Alchemy\Phrasea\Model\Entities\FeedEntry; use Alchemy\Phrasea\Model\Entities\FeedEntry;
use Alchemy\Phrasea\Application; use Alchemy\Phrasea\Application;

View File

@@ -0,0 +1,19 @@
<?php
namespace Alchemy\Phrasea\SearchEngine\Elastic\Search;
class Escaper
{
public function escapeWord($value)
{
// Strip double quotes from values to prevent broken queries
// TODO escape double quotes when it will be supported in query parser
$value = str_replace('/["\(\)\[\]]+/u', ' ', $value);
if (preg_match('/[\s\(\)\[\]]/u', $value)) {
return sprintf('"%s"', $value);
}
return $value;
}
}