This commit is contained in:
2026-05-08 00:05:51 +08:00
parent 549b706fcc
commit ed70a140a2
40 changed files with 5590 additions and 36 deletions
@@ -16,6 +16,7 @@ class OpenSearchChunkIndex
$index = $this->indexName();
if ($client->indices()->exists(['index' => $index])) {
$this->ensureProperties($client, $index);
return;
}
@@ -64,6 +65,7 @@ class OpenSearchChunkIndex
'page_start' => ['type' => 'integer'],
'page_end' => ['type' => 'integer'],
'title' => $this->textWithKeyword(),
'summary' => ['type' => 'text'],
'source' => $this->textWithKeyword(),
'author' => $this->textWithKeyword(),
'year' => ['type' => 'integer'],
@@ -93,6 +95,31 @@ class OpenSearchChunkIndex
return $this->client ?? (new OpenSearchClientFactory())->make();
}
private function ensureProperties(Client $client, string $index): void
{
$mapping = $client->indices()->getMapping(['index' => $index]);
$existing = $mapping[$index]['mappings']['properties'] ?? [];
$desired = $this->mapping()['mappings']['properties'] ?? [];
$missing = [];
foreach ($desired as $field => $definition) {
if (!array_key_exists($field, $existing)) {
$missing[$field] = $definition;
}
}
if ($missing === []) {
return;
}
$client->indices()->putMapping([
'index' => $index,
'body' => [
'properties' => $missing,
],
]);
}
private function indexName(): string
{
return config('opensearch.indices.chunks', 'proofdb_chunks');