Explorar o código

docs: Add reindexing to importing data example (#2656)

added searchService to reindex after importing
gspoon666 hai 1 ano
pai
achega
4bbea6afcf
Modificáronse 1 ficheiros con 8 adicións e 1 borrados
  1. 8 1
      docs/docs/guides/developer-guide/importing-data/index.md

+ 8 - 1
docs/docs/guides/developer-guide/importing-data/index.md

@@ -311,7 +311,8 @@ import {
     LanguageCode,
     ParsedProductWithVariants,
     RequestContext, RequestContextService,
-    TransactionalConnection, User
+    TransactionalConnection, User,
+    SearchService,
 } from '@vendure/core';
 import { createClient, OldCommerceProduct } from '@old-commerce/client';
 
@@ -344,6 +345,9 @@ async function importData() {
     // Most service methods require a RequestContext, so we'll create one here.
     const ctx = await getSuperadminContext(app);
 
+    // To reindex after importing products
+    const searchService = app.get(SearchService);
+
     // Fetch all the products to import from the OldCommerce API
     const productsToImport: OldCommerceProduct[] = await client.getAllProducts();
 
@@ -387,6 +391,9 @@ async function importData() {
         console.log(`Imported ${progress.imported} of ${importRows.length} products`);
     });
 
+    // Rebuild search index 
+    await searchService.reindex(ctx);
+
     // Close the app
     await app.close();
 }