From fc0e71e28e49d9cdc84fadfda40692bdfc415a6c Mon Sep 17 00:00:00 2001 From: Yuriy Andamasov Date: Fri, 22 May 2026 11:40:40 +0300 Subject: Engine: Add buildIndexMappings() helper (single typeless mapping) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Single 'properties' block, documentType as a keyword field inside it, no include_in_all anywhere (the field was removed in ES 6). Relationships emit as keyword fields with doc_values: false, matching the bundled engine's ES-5-mode behavior. Field-data multi-analyzer shape (raw, keywords, stems) preserved. 🤖 Generated by [robots](https://vyos.io) --- ...SElasticModernFulltextStorageEngineTestCase.php | 54 ++++++++++++++++++++++ .../VyOSElasticModernFulltextStorageEngine.php | 47 +++++++++++++++++++ 2 files changed, 101 insertions(+) (limited to 'src') diff --git a/src/__tests__/VyOSElasticModernFulltextStorageEngineTestCase.php b/src/__tests__/VyOSElasticModernFulltextStorageEngineTestCase.php index ff4ade8..ab6f5c6 100644 --- a/src/__tests__/VyOSElasticModernFulltextStorageEngineTestCase.php +++ b/src/__tests__/VyOSElasticModernFulltextStorageEngineTestCase.php @@ -112,4 +112,58 @@ final class VyOSElasticModernFulltextStorageEngineTestCase $filter); } + public function testBuildIndexMappingsShape() { + $engine = id(new VyOSElasticModernFulltextStorageEngine()) + ->setVersion(7); + + $doc_types = array('TASK', 'DREV'); + $fields = array('title', 'body', 'comment'); + $relationships = array('authorPHID', 'projectPHID'); + $mappings = $engine->buildIndexMappings( + $doc_types, $fields, $relationships, 'text'); + + // Single typeless mapping with one 'properties' block. + $this->assertTrue(isset($mappings['properties'])); + $this->assertFalse(isset($mappings['TASK'])); + $this->assertFalse(isset($mappings['DREV'])); + + // Field properties exist with the multi-analyzer shape. + $this->assertTrue(isset($mappings['properties']['title'])); + $this->assertEqual('text', $mappings['properties']['title']['type']); + $this->assertTrue( + isset($mappings['properties']['title']['fields']['raw'])); + $this->assertTrue( + isset($mappings['properties']['title']['fields']['keywords'])); + $this->assertTrue( + isset($mappings['properties']['title']['fields']['stems'])); + + // Relationships emit as keyword fields with doc_values:false. + $this->assertEqual( + 'keyword', + $mappings['properties']['authorPHID']['type']); + $this->assertEqual( + false, + $mappings['properties']['authorPHID']['doc_values']); + $this->assertEqual( + 'date', + $mappings['properties']['authorPHID_ts']['type']); + + // No include_in_all anywhere. + $this->assertFalse( + isset($mappings['properties']['authorPHID']['include_in_all'])); + + // documentType is a keyword field inside properties. + $this->assertEqual( + 'keyword', + $mappings['properties']['documentType']['type']); + + // Standard date fields present. + $this->assertEqual( + 'date', + $mappings['properties']['dateCreated']['type']); + $this->assertEqual( + 'date', + $mappings['properties']['lastModified']['type']); + } + } diff --git a/src/engine/VyOSElasticModernFulltextStorageEngine.php b/src/engine/VyOSElasticModernFulltextStorageEngine.php index 316a02b..16c519c 100644 --- a/src/engine/VyOSElasticModernFulltextStorageEngine.php +++ b/src/engine/VyOSElasticModernFulltextStorageEngine.php @@ -48,6 +48,53 @@ abstract class VyOSElasticModernFulltextStorageEngine ); } + public function buildIndexMappings( + array $doc_types, array $fields, array $relationships, $text_type) { + + $properties = array(); + + foreach ($fields as $field) { + $properties[$field] = array( + 'type' => $text_type, + 'fields' => array( + 'raw' => array( + 'type' => $text_type, + 'analyzer' => 'english_exact', + 'search_analyzer' => 'english', + 'search_quote_analyzer' => 'english_exact', + ), + 'keywords' => array( + 'type' => $text_type, + 'analyzer' => 'letter_stop', + ), + 'stems' => array( + 'type' => $text_type, + 'analyzer' => 'english_stem', + ), + ), + ); + } + + foreach ($relationships as $rel) { + $properties[$rel] = array( + 'type' => 'keyword', + 'doc_values' => false, + ); + $properties[$rel.'_ts'] = array( + 'type' => 'date', + ); + } + + $properties['documentType'] = array('type' => 'keyword'); + $properties['dateCreated'] = array('type' => 'date'); + $properties['lastModified'] = array('type' => 'date'); + + // The $doc_types parameter is part of the signature for symmetry + // with the bundled engine's per-type loop, but the typeless API + // emits one mapping shared across all doc types. + return array('properties' => $properties); + } + public function getEngineIdentifier() { return 'elasticsearch-modern'; } -- cgit v1.2.3