diff --git a/src/services/Indexes.php b/src/services/Indexes.php index f78aca2..76d5f5b 100644 --- a/src/services/Indexes.php +++ b/src/services/Indexes.php @@ -461,15 +461,21 @@ public function buildMapping(): array $mapping = []; $predefinedAttributes = [ - 'title', - 'slug', - ]; - - foreach ($predefinedAttributes as $attribute) { - $mapping[$fieldPrefix . 'attribute_' . $attribute] = [ + 'title' => [ + 'type' => 'text', + 'analyzer' => 'standard', + ], + 'slug' => [ 'type' => 'text', 'analyzer' => 'standard', - ]; + ], + 'postDate' => [ + 'type' => 'date', + ], + ]; + + foreach ($predefinedAttributes as $attribute => $config) { + $mapping[$fieldPrefix . 'attribute_' . $attribute] = $config; } /** 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);