Skip to content

Commit cf3f248

Browse files
authored
Fix duplication in the search results (#8409)
* Use temporary index + swap * Fix typescript error * Fix conflict on lock
1 parent 7aa8529 commit cf3f248

File tree

4 files changed

+175
-185
lines changed

4 files changed

+175
-185
lines changed

apps/site/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@
4141
"@opentelemetry/api-logs": "~0.206.0",
4242
"@opentelemetry/instrumentation": "~0.206.0",
4343
"@opentelemetry/resources": "~1.30.1",
44-
"@orama/core": "^1.2.13",
45-
"@orama/ui": "^1.5.3",
4644
"@opentelemetry/sdk-logs": "~0.206.0",
45+
"@orama/core": "^1.2.14",
46+
"@orama/ui": "^1.5.3",
4747
"@radix-ui/react-tabs": "^1.1.13",
4848
"@radix-ui/react-tooltip": "^1.2.8",
4949
"@tailwindcss/postcss": "~4.1.17",

apps/site/scripts/orama-search/sync-orama-cloud.mjs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,17 @@ import { OramaCloud } from '@orama/core';
33
import { getDocuments } from './get-documents.mjs';
44
import { ORAMA_SYNC_BATCH_SIZE } from '../../next.constants.mjs';
55

6-
// The following follows the instructions at https://docs.orama.com/cloud/data-sources/custom-integrations/webhooks
6+
// The following follows the instructions at https://docs.oramasearch.com/docs/cloud/data-sources/rest-APIs/using-rest-apis
77

88
const orama = new OramaCloud({
99
projectId: process.env.NEW_ORAMA_PROJECT_ID || '',
1010
apiKey: process.env.NEW_ORAMA_PRIVATE_API_KEY || '',
1111
});
1212

1313
const datasource = orama.dataSource(process.env.NEW_ORAMA_DATASOURCE_ID || '');
14+
15+
// Create a temporary index to perform the insertions
16+
const temporary = await datasource.createTemporaryIndex();
1417
const documents = await getDocuments();
1518

1619
console.log(`Syncing ${documents.length} documents to Orama Cloud index`);
@@ -27,16 +30,15 @@ const runUpdate = async () => {
2730

2831
console.log(`Sending ${batches.length} batches of ${batchSize} documents`);
2932

33+
// Insert documents batch by batch into the temporary index
3034
for (const batch of batches) {
31-
await datasource.insertDocuments(batch);
35+
await temporary.insertDocuments(batch);
3236
}
37+
38+
// Once all documents are inserted into the temporary index, we swap it with the live one atomically.
39+
await temporary.swap();
3340
};
3441

35-
// Now we proceed to call the APIs in order.
36-
// The previous implementation used to empty the index before inserting new documents
37-
// to remove documents that are no longer in the source.
38-
// The new API from @orama/core might have a different approach for full sync.
39-
// Based on the provided examples, we are now only running the update.
4042
await runUpdate();
4143

4244
console.log('Orama Cloud sync completed successfully!');

packages/ui-components/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
"tailwindcss": "catalog:"
5454
},
5555
"devDependencies": {
56-
"@orama/core": "^1.2.13",
56+
"@orama/core": "^1.2.14",
5757
"@storybook/addon-styling-webpack": "^3.0.0",
5858
"@storybook/addon-themes": "^10.1.4",
5959
"@storybook/addon-webpack5-compiler-swc": "^4.0.2",

0 commit comments

Comments
 (0)