summaryrefslogtreecommitdiff
path: root/src/engine/VyOSElasticModernFulltextStorageEngine.php
diff options
context:
space:
mode:
authorYuriy Andamasov <yuriy@vyos.io>2026-05-23 13:31:46 +0300
committerYuriy Andamasov <yuriy@vyos.io>2026-05-23 13:31:46 +0300
commitde83584f8b782bde516d6b39f9f1bc4214585058 (patch)
treeef210a295958021e0c3f2c078aec6d415d92c35c /src/engine/VyOSElasticModernFulltextStorageEngine.php
parentb05490e9be22d8e9ac576ac62b646ddd9b5f3ffe (diff)
downloadphorge-elasticsearch-modern-de83584f8b782bde516d6b39f9f1bc4214585058.tar.gz
phorge-elasticsearch-modern-de83584f8b782bde516d6b39f9f1bc4214585058.zip
E5 fixup: detect intra-key duplicates in buildIndexMappings(); add collision tests
🤖 Generated by [robots](https://vyos.io)
Diffstat (limited to 'src/engine/VyOSElasticModernFulltextStorageEngine.php')
-rw-r--r--src/engine/VyOSElasticModernFulltextStorageEngine.php21
1 files changed, 17 insertions, 4 deletions
diff --git a/src/engine/VyOSElasticModernFulltextStorageEngine.php b/src/engine/VyOSElasticModernFulltextStorageEngine.php
index f798e4b..fe88adc 100644
--- a/src/engine/VyOSElasticModernFulltextStorageEngine.php
+++ b/src/engine/VyOSElasticModernFulltextStorageEngine.php
@@ -55,10 +55,10 @@ abstract class VyOSElasticModernFulltextStorageEngine
// Caller-supplied $fields or $relationships must not shadow them.
static $reserved = array('documentType', 'dateCreated', 'lastModified');
- $all_caller_keys = array_merge(
- $fields,
- $relationships,
- array_map(function($r) { return $r.'_ts'; }, $relationships));
+ $rel_ts_keys = array_map(function($r) { return $r.'_ts'; }, $relationships);
+ $all_caller_keys = array_merge($fields, $relationships, $rel_ts_keys);
+
+ // Check for caller-supplied names that shadow reserved fields.
$collisions = array_intersect($all_caller_keys, $reserved);
if ($collisions) {
throw new Exception(
@@ -68,6 +68,19 @@ abstract class VyOSElasticModernFulltextStorageEngine
implode('", "', array_values($collisions))));
}
+ // Check for duplicates within caller-supplied keys themselves
+ // (e.g. a field named "foo_ts" that would clash with relationship "foo"'s
+ // implicit timestamp slot).
+ $counts = array_count_values($all_caller_keys);
+ $duplicates = array_keys(array_filter($counts, function($c) { return $c > 1; }));
+ if ($duplicates) {
+ throw new Exception(
+ pht(
+ 'buildIndexMappings(): caller-supplied key(s) "%s" appear more '.
+ 'than once (check for field/relationship/timestamp-slot collisions).',
+ implode('", "', $duplicates)));
+ }
+
$properties = array();
foreach ($fields as $field) {