From e3447d31fda1cf1a89179dda233bd2d1e1e28d30 Mon Sep 17 00:00:00 2001 From: Johannes Wachter Date: Fri, 19 Aug 2016 13:28:47 +0200 Subject: [PATCH] updated mapping for elastic index --- Controller/ArticleController.php | 5 ++-- Document/ArticleOngrDocument.php | 40 ++++++++++++++++++++++++++++---- Document/ExcerptOngrObject.php | 30 +++++++++++++++++++++--- Document/SeoOngrObject.php | 40 ++++++++++++++++++++++++++++---- 4 files changed, 102 insertions(+), 13 deletions(-) diff --git a/Controller/ArticleController.php b/Controller/ArticleController.php index 78ddfda3a..c127526fd 100644 --- a/Controller/ArticleController.php +++ b/Controller/ArticleController.php @@ -16,6 +16,7 @@ use ONGR\ElasticsearchBundle\Service\Manager; use ONGR\ElasticsearchDSL\Query\FuzzyQuery; use ONGR\ElasticsearchDSL\Query\TermQuery; +use ONGR\ElasticsearchDSL\Query\WildcardQuery; use ONGR\ElasticsearchDSL\Sort\FieldSort; use Sulu\Bundle\ArticleBundle\Document\ArticleOngrDocument; use Sulu\Bundle\ArticleBundle\Document\Form\ArticleDocumentType; @@ -83,9 +84,9 @@ public function cgetAction(Request $request) $repository = $manager->getRepository(ArticleOngrDocument::class); $search = $repository->createSearch(); - if (null !== ($searchPattern = $restHelper->getSearchPattern())) { + if (!empty($searchPattern = $restHelper->getSearchPattern())) { foreach ($restHelper->getSearchFields() as $searchField) { - $search->addQuery(new FuzzyQuery($searchField, $searchPattern)); + $search->addQuery(new WildcardQuery($searchField, '*' . $searchPattern . '*')); } } diff --git a/Document/ArticleOngrDocument.php b/Document/ArticleOngrDocument.php index 78b1ad827..cb8b87a94 100644 --- a/Document/ArticleOngrDocument.php +++ b/Document/ArticleOngrDocument.php @@ -40,14 +40,30 @@ class ArticleOngrDocument /** * @var string * - * @Property(type="string") + * @Property( + * type="string", + * options={ + * "fields"={ + * "raw"={"type"="string", "index"="not_analyzed"}, + * "value"={"type"="string"} + * } + * } + * ) */ protected $title; /** * @var string * - * @Property(type="string") + * @Property( + * type="string", + * options={ + * "fields"={ + * "raw"={"type"="string", "index"="not_analyzed"}, + * "value"={"type"="string"} + * } + * } + * ) */ protected $routePath; @@ -61,14 +77,30 @@ class ArticleOngrDocument /** * @var string * - * @Property(type="string") + * @Property( + * type="string", + * options={ + * "fields"={ + * "raw"={"type"="string", "index"="not_analyzed"}, + * "value"={"type"="string"} + * } + * } + * ) */ protected $changer; /** * @var string * - * @Property(type="string") + * @Property( + * type="string", + * options={ + * "fields"={ + * "raw"={"type"="string", "index"="not_analyzed"}, + * "value"={"type"="string"} + * } + * } + * ) */ protected $creator; diff --git a/Document/ExcerptOngrObject.php b/Document/ExcerptOngrObject.php index 240ef5e37..3ed432dd2 100644 --- a/Document/ExcerptOngrObject.php +++ b/Document/ExcerptOngrObject.php @@ -25,21 +25,45 @@ class ExcerptOngrObject /** * @var string * - * @Property(type="string") + * @Property( + * type="string", + * options={ + * "fields"={ + * "raw"={"type"="string", "index"="not_analyzed"}, + * "value"={"type"="string"} + * } + * } + * ) */ public $title; /** * @var string * - * @Property(type="string") + * @Property( + * type="string", + * options={ + * "fields"={ + * "raw"={"type"="string", "index"="not_analyzed"}, + * "value"={"type"="string"} + * } + * } + * ) */ public $more; /** * @var string * - * @Property(type="string") + * @Property( + * type="string", + * options={ + * "fields"={ + * "raw"={"type"="string", "index"="not_analyzed"}, + * "value"={"type"="string"} + * } + * } + * ) */ public $description; diff --git a/Document/SeoOngrObject.php b/Document/SeoOngrObject.php index cae3eb5a3..dbf66c18c 100644 --- a/Document/SeoOngrObject.php +++ b/Document/SeoOngrObject.php @@ -24,28 +24,60 @@ class SeoOngrObject /** * @var string * - * @Property(type="string") + * @Property( + * type="string", + * options={ + * "fields"={ + * "raw"={"type"="string", "index"="not_analyzed"}, + * "value"={"type"="string"} + * } + * } + * ) */ public $title; /** * @var string * - * @Property(type="string") + * @Property( + * type="string", + * options={ + * "fields"={ + * "raw"={"type"="string", "index"="not_analyzed"}, + * "value"={"type"="string"} + * } + * } + * ) */ public $description; /** * @var string * - * @Property(type="string") + * @Property( + * type="string", + * options={ + * "fields"={ + * "raw"={"type"="string", "index"="not_analyzed"}, + * "value"={"type"="string"} + * } + * } + * ) */ public $keywords; /** * @var string * - * @Property(type="string") + * @Property( + * type="string", + * options={ + * "fields"={ + * "raw"={"type"="string", "index"="not_analyzed"}, + * "value"={"type"="string"} + * } + * } + * ) */ public $canonicalUrl;