summaryrefslogtreecommitdiff
path: root/src/__tests__/VyOSElasticModernFulltextStorageEngineTestCase.php
diff options
context:
space:
mode:
authorYuriy Andamasov <yuriy@andamasov.com>2026-05-23 14:23:27 +0300
committerGitHub <noreply@github.com>2026-05-23 14:23:27 +0300
commitc1a972d45d60f5d721156d7dfb7a958f2e7b9abc (patch)
treeef210a295958021e0c3f2c078aec6d415d92c35c /src/__tests__/VyOSElasticModernFulltextStorageEngineTestCase.php
parent132217de05911823c2fcec2785fc38918442081c (diff)
parentde83584f8b782bde516d6b39f9f1bc4214585058 (diff)
downloadphorge-elasticsearch-modern-c1a972d45d60f5d721156d7dfb7a958f2e7b9abc.tar.gz
phorge-elasticsearch-modern-c1a972d45d60f5d721156d7dfb7a958f2e7b9abc.zip
Merge pull request #8 from vyos/task/e5-buildindexmappings
E5: Add buildIndexMappings() helper
Diffstat (limited to 'src/__tests__/VyOSElasticModernFulltextStorageEngineTestCase.php')
-rw-r--r--src/__tests__/VyOSElasticModernFulltextStorageEngineTestCase.php124
1 files changed, 124 insertions, 0 deletions
diff --git a/src/__tests__/VyOSElasticModernFulltextStorageEngineTestCase.php b/src/__tests__/VyOSElasticModernFulltextStorageEngineTestCase.php
index ff4ade8..e3daab4 100644
--- a/src/__tests__/VyOSElasticModernFulltextStorageEngineTestCase.php
+++ b/src/__tests__/VyOSElasticModernFulltextStorageEngineTestCase.php
@@ -112,4 +112,128 @@ final class VyOSElasticModernFulltextStorageEngineTestCase
$filter);
}
+ public function testBuildIndexMappingsShape() {
+ $engine = $this->newEngine()->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']));
+
+ // All three text fields have the multi-analyzer shape.
+ foreach (array('title', 'body', 'comment') as $field) {
+ $this->assertTrue(
+ isset($mappings['properties'][$field]),
+ pht('Field "%s" missing from mappings.', $field));
+ $this->assertEqual(
+ 'text',
+ $mappings['properties'][$field]['type'],
+ pht('Field "%s" should be type text.', $field));
+ $this->assertTrue(
+ isset($mappings['properties'][$field]['fields']['raw']),
+ pht('Field "%s" missing raw sub-field.', $field));
+ $this->assertTrue(
+ isset($mappings['properties'][$field]['fields']['keywords']),
+ pht('Field "%s" missing keywords sub-field.', $field));
+ $this->assertTrue(
+ isset($mappings['properties'][$field]['fields']['stems']),
+ pht('Field "%s" missing stems sub-field.', $field));
+ }
+
+ // Both relationships emit as keyword fields with doc_values:false.
+ foreach (array('authorPHID', 'projectPHID') as $rel) {
+ $this->assertEqual(
+ 'keyword',
+ $mappings['properties'][$rel]['type'],
+ pht('Relationship "%s" should be keyword type.', $rel));
+ $this->assertEqual(
+ false,
+ $mappings['properties'][$rel]['doc_values'],
+ pht('Relationship "%s" should have doc_values:false.', $rel));
+ $this->assertEqual(
+ 'date',
+ $mappings['properties'][$rel.'_ts']['type'],
+ pht('Relationship "%s" missing timestamp field.', $rel));
+ // No include_in_all anywhere.
+ $this->assertFalse(
+ isset($mappings['properties'][$rel]['include_in_all']),
+ pht('Relationship "%s" should not have include_in_all.', $rel));
+ }
+
+ // 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']);
+ }
+
+ public function testBuildIndexMappingsRejectsReservedFieldName() {
+ $engine = $this->newEngine()->setVersion(7);
+ $caught = null;
+ try {
+ $engine->buildIndexMappings(
+ array(), array('documentType'), array(), 'text');
+ } catch (Exception $e) {
+ $caught = $e;
+ }
+ $this->assertTrue(
+ $caught !== null,
+ pht('Expected exception when field name collides with reserved key.'));
+ }
+
+ public function testBuildIndexMappingsRejectsReservedRelationshipName() {
+ $engine = $this->newEngine()->setVersion(7);
+ $caught = null;
+ try {
+ $engine->buildIndexMappings(
+ array(), array(), array('lastModified'), 'text');
+ } catch (Exception $e) {
+ $caught = $e;
+ }
+ $this->assertTrue(
+ $caught !== null,
+ pht('Expected exception when relationship name collides with reserved key.'));
+ }
+
+ public function testBuildIndexMappingsRejectsFooTsClash() {
+ // A field named "foo_ts" would clash with the timestamp slot auto-generated
+ // for a relationship named "foo".
+ $engine = $this->newEngine()->setVersion(7);
+ $caught = null;
+ try {
+ $engine->buildIndexMappings(
+ array(), array('foo_ts'), array('foo'), 'text');
+ } catch (Exception $e) {
+ $caught = $e;
+ }
+ $this->assertTrue(
+ $caught !== null,
+ pht('Expected exception for field/relationship timestamp-slot collision.'));
+ }
+
+ public function testBuildIndexMappingsEmptyInputsYieldStandardFields() {
+ $engine = $this->newEngine()->setVersion(7);
+ $mappings = $engine->buildIndexMappings(array(), array(), array(), 'text');
+ $this->assertTrue(isset($mappings['properties']['documentType']));
+ $this->assertTrue(isset($mappings['properties']['dateCreated']));
+ $this->assertTrue(isset($mappings['properties']['lastModified']));
+ $this->assertEqual(
+ 'keyword', $mappings['properties']['documentType']['type']);
+ $this->assertEqual('date', $mappings['properties']['dateCreated']['type']);
+ $this->assertEqual('date', $mappings['properties']['lastModified']['type']);
+ }
+
}