Skip to content

Domain Model

@nx/search không sở hữu bảng PostgreSQL nào. "Domain" của nó là tập các Typesense collection — projection đọc denormalized của các bảng nguồn trong schema public, pricing, và inventory. Định nghĩa schema nằm trong src/configurations/<entity>.collection.ts (shape dùng chung trong schema-fragments.ts).

1. ERD đầy đủ

Bảng source CDC (trái) project vào Typesense collection (phải). Liền = direct doc source; nét đứt = cascade-only.

2. Entities (Collections)

Mỗi block một collection. Mỗi cái là một Typesense document khá phẳng; i18n { en, vi } được flatten thành field.en / field.vi. queryBy liệt kê các trường text có thể tìm; trường facetable có thể filter.

organizers

Thuộc tínhGiá trị
Sourcepublic.Organizer (direct)
Configsrc/configurations/organizer.collection.ts
Doc idOrganizer.id
queryByname.en, name.vi, description.en, description.vi, slug, identifier
Relationsparent (organizers, hydration)
Embeddingoptional

merchants

Thuộc tínhGiá trị
Sourcepublic.Merchant (direct)
Configsrc/configurations/merchant.collection.ts
Doc idMerchant.id
queryByname.en, name.vi, description.en, description.vi, slug, identifier
Relationsorganizer (native), parent (merchants, hydration)

categories

Thuộc tínhGiá trị
Sourcepublic.Category (direct)
Configsrc/configurations/category.collection.ts
Doc idCategory.id
queryByname.en, name.vi, description.en, description.vi
Relationsmerchant (native)

devices

Thuộc tínhGiá trị
Sourcepublic.Device (direct)
Configsrc/configurations/device.collection.ts
Doc idDevice.id
queryByname.*, identifier, code
Relationsorganizer (native), merchant (native)

sale-channels

Thuộc tínhGiá trị
Sourcepublic.SaleChannel (direct)
Configsrc/configurations/sale-channel.collection.ts
Doc idSaleChannel.id
queryByname.en, name.vi, slug, identifier
Relationsmerchant (native), parent (sale-channels, hydration)

products

Thuộc tínhGiá trị
Sourcepublic.Product + public.ProductInfo (i18n) — cả hai direct (info là partial update)
CascadeProductCategorycategoryIds[]
Configsrc/configurations/product.collection.ts (+ product-info-mapper)
Doc idProduct.id
queryByidentifier, slug, info.name.{en,vi}, info.description.{en,vi}, merchant_name.{en,vi}, organizer_name.{en,vi}, sale_channel_names
Facetsstatus, merchantId (ref merchants.id), categoryIds[], parentId, tên parent denormalized
Relationsmerchant (native), parent (products, hydration)
Embeddingtrường embedding từ [identifier, slug]

product-variants

Thuộc tínhGiá trị
Sourcepublic.ProductVariant (direct) + ProductVariantInfo
CascadeProductCategory (categoryIds), MetaLink (metaLinks), FareSet/Fare (fareSet, defaultPrice), ProductBundler (comboItems)
Configsrc/configurations/product-variant.collection.ts
Doc idProductVariant.id
Relationsproduct (native), merchant (native)

inventories

Thuộc tínhGiá trị
Sourceinventory.InventoryStock (direct, doc grain)
CascadeInventoryItem, InventoryLocation, InventoryIdentifier, Material
Configsrc/configurations/inventory.collection.ts
Doc idInventoryStock.id (== inventoryStockId)
queryByitem.name.{en,vi}, location.name.{en,vi}, identifiers.value, stock.lotNumber, stock.serialNumber, item.slug, item.description.{en,vi}
Structurenhóm lồng item / location / stock; identifiers[] (scheme-agnostic); flags[] (boolean dẫn xuất)
Notesflags.isExpired / isExpiringSoon bị stale — refresh bởi reindex định kỳ hoặc range lúc-query

3. Bất biến xuyên entity

Bất biếnCách thực thi
Document id luôn bằng id dòng nguồnMapper extractDocumentId / idField
Dòng nguồn soft-deleted ⇒ document vắng mặtMapper trả về nullCDCService xóa
Event CDC sai thứ tự không bao giờ ghi đè state mới hơnGuard LSN (source_lsn) + so sánh deleted_at
products.categoryIds phản ánh mọi dòng ProductCategoryCascade fan-out + enrichment (không phải row mapper)
Doc inventories là một-cho-mỗi-InventoryStock, item/location denormalizedCascade từ InventoryItem/InventoryLocation
Trường reference của Typesense phải ở top-levelSchema đặt merchantId, inventoryItemId, v.v. ở top level

4. Hành vi Soft-delete

Hành viChi tiết
Nguồn chân lýPostgreSQL deletedAt (do source service sở hữu)
Hiệu ứng searchMapper phát hiện deletedAt != null → emit delete tới Typesense
Đọc mặc địnhDòng soft-deleted không có document, nên không bao giờ xuất hiện trong kết quả
Hard-deleteMột op Debezium d cũng xóa document
RestoreMột event CDC không-deleted sau đó re-upsert document

5. Trang liên quan

Proprietary and Confidential. Unauthorized copying, distribution, or use of this software is strictly prohibited.