暂存
This commit is contained in:
@@ -7,6 +7,22 @@ use support\Db;
|
||||
|
||||
class ChunkSearchIndexRepository
|
||||
{
|
||||
public function resetEmbeddedChunksToPending(?string $archiveUid = null): int
|
||||
{
|
||||
$query = Db::table('chunks')
|
||||
->where('embedding_status', EmbeddingStatus::EMBEDDED);
|
||||
|
||||
if ($archiveUid !== null && trim($archiveUid) !== '') {
|
||||
$query->where('archive_uid', trim($archiveUid));
|
||||
}
|
||||
|
||||
return $query->update([
|
||||
'search_index_status' => SearchIndexStatus::PENDING,
|
||||
'search_index_error' => null,
|
||||
'search_index_updated_at' => null,
|
||||
]);
|
||||
}
|
||||
|
||||
public function queuePendingArchiveTasks(int $limit): array
|
||||
{
|
||||
$statuses = [
|
||||
@@ -63,6 +79,7 @@ class ChunkSearchIndexRepository
|
||||
'chunks.created_time',
|
||||
'chunks.updated_time',
|
||||
'archives.title',
|
||||
'archives.summary',
|
||||
'archives.source',
|
||||
'archives.author',
|
||||
'archives.year',
|
||||
@@ -105,6 +122,7 @@ class ChunkSearchIndexRepository
|
||||
'page_start' => $row->page_start === null ? null : (int) $row->page_start,
|
||||
'page_end' => $row->page_end === null ? null : (int) $row->page_end,
|
||||
'title' => $row->title,
|
||||
'summary' => $row->summary,
|
||||
'source' => $row->source,
|
||||
'author' => $row->author,
|
||||
'year' => $row->year === null ? null : (int) $row->year,
|
||||
|
||||
@@ -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');
|
||||
|
||||
@@ -39,6 +39,7 @@ class OpenSearchSearchService
|
||||
'fields' => [
|
||||
'text^4',
|
||||
'title^3',
|
||||
'summary^2',
|
||||
'source^2',
|
||||
'author^2',
|
||||
'series^2',
|
||||
@@ -219,6 +220,7 @@ class OpenSearchSearchService
|
||||
'page_start' => $source['page_start'] ?? null,
|
||||
'page_end' => $source['page_end'] ?? null,
|
||||
'title' => $source['title'] ?? null,
|
||||
'summary' => $source['summary'] ?? null,
|
||||
'source' => $source['source'] ?? null,
|
||||
'author' => $source['author'] ?? null,
|
||||
'year' => $source['year'] ?? null,
|
||||
@@ -322,6 +324,7 @@ class OpenSearchSearchService
|
||||
'page_start',
|
||||
'page_end',
|
||||
'title',
|
||||
'summary',
|
||||
'source',
|
||||
'author',
|
||||
'year',
|
||||
|
||||
Reference in New Issue
Block a user