From 35ba795bac6d942b664e60a1c8dab367e3cce2de Mon Sep 17 00:00:00 2001 From: Len van Essen Date: Fri, 23 Sep 2022 10:32:10 +0200 Subject: [PATCH 1/3] Include postdate in Mapping --- src/services/Indexes.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/services/Indexes.php b/src/services/Indexes.php index f78aca2..7e18722 100644 --- a/src/services/Indexes.php +++ b/src/services/Indexes.php @@ -461,13 +461,14 @@ public function buildMapping(): array $mapping = []; $predefinedAttributes = [ - 'title', - 'slug', + 'title' => 'text', + 'slug' => 'text', + 'postDate' => 'date' ]; - foreach ($predefinedAttributes as $attribute) { + foreach ($predefinedAttributes as $attribute => $type) { $mapping[$fieldPrefix . 'attribute_' . $attribute] = [ - 'type' => 'text', + 'type' => $type, 'analyzer' => 'standard', ]; } From bb345fa66cf045a46074e665abd86b3331d0b0ac Mon Sep 17 00:00:00 2001 From: Len van Essen Date: Fri, 23 Sep 2022 10:53:19 +0200 Subject: [PATCH 2/3] Fix analyzer config --- src/services/Indexes.php | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/services/Indexes.php b/src/services/Indexes.php index 7e18722..76d5f5b 100644 --- a/src/services/Indexes.php +++ b/src/services/Indexes.php @@ -461,16 +461,21 @@ public function buildMapping(): array $mapping = []; $predefinedAttributes = [ - 'title' => 'text', - 'slug' => 'text', - 'postDate' => 'date' + 'title' => [ + 'type' => 'text', + 'analyzer' => 'standard', + ], + 'slug' => [ + 'type' => 'text', + 'analyzer' => 'standard', + ], + 'postDate' => [ + 'type' => 'date', + ], ]; - foreach ($predefinedAttributes as $attribute => $type) { - $mapping[$fieldPrefix . 'attribute_' . $attribute] = [ - 'type' => $type, - 'analyzer' => 'standard', - ]; + foreach ($predefinedAttributes as $attribute => $config) { + $mapping[$fieldPrefix . 'attribute_' . $attribute] = $config; } /** From 713fae222f2430cdde5a470245e1324f5bc73985 Mon Sep 17 00:00:00 2001 From: Len van Essen Date: Fri, 23 Sep 2022 11:04:36 +0200 Subject: [PATCH 3/3] Add to indexation --- src/services/Search.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/services/Search.php b/src/services/Search.php index e0562e8..7f26971 100644 --- a/src/services/Search.php +++ b/src/services/Search.php @@ -71,6 +71,10 @@ public function indexElementAttributes(ElementInterface $element, ?array $fieldH $keywords['attribute_' . $attribute] = $element->getSearchKeywords($attribute); } + if(isset($element->postDate) && $element->postDate instanceof \DateTime) { + $keywords['attribute_postDate'] = $element->postDate->format(\DateTime::ATOM); + } + // Update the custom fields' keywords foreach ($updateFields as $field) { $fieldValue = $element->getFieldValue($field->handle);