feat(medusa-plugin-meilisearch): Update + improve Meilisearch plugin (#3377)
* feat(medusa-plugin-meilisearch): Upgrade meilisearch deps + migrate plugin to TS * fix version * Remove transaction base service from search service * Create .changeset/strange-mails-pump.md * Backward compatibility * Address PR feedback * Fix folder structure * Update readme * Move types * fix deps * Change version in changeset --------- Co-authored-by: adrien2p <adrien.deperetti@gmail.com>
This commit is contained in:
co-authored by
adrien2p
parent
4213326fe8
commit
7e17e0ddc2
@@ -1,29 +1,35 @@
|
||||
import EventBusService from "../services/event-bus"
|
||||
import { SEARCH_INDEX_EVENT } from "../loaders/search-index"
|
||||
import ProductService from "../services/product"
|
||||
import { indexTypes } from "medusa-core-utils"
|
||||
import { Product } from "../models"
|
||||
import { ISearchService } from "../interfaces"
|
||||
import ProductCategoryFeatureFlag from "../loaders/feature-flags/product-categories"
|
||||
import { SEARCH_INDEX_EVENT } from "../loaders/search-index"
|
||||
import { Product } from "../models"
|
||||
import EventBusService from "../services/event-bus"
|
||||
import ProductService from "../services/product"
|
||||
import { FlagRouter } from "../utils/flag-router"
|
||||
|
||||
type InjectedDependencies = {
|
||||
eventBusService: EventBusService
|
||||
searchService: ISearchService
|
||||
productService: ProductService
|
||||
featureFlagRouter: FlagRouter
|
||||
}
|
||||
|
||||
class SearchIndexingSubscriber {
|
||||
private readonly eventBusService_: EventBusService
|
||||
private readonly searchService_: ISearchService
|
||||
private readonly productService_: ProductService
|
||||
private readonly featureFlagRouter_: FlagRouter
|
||||
|
||||
constructor({
|
||||
eventBusService,
|
||||
searchService,
|
||||
productService,
|
||||
featureFlagRouter,
|
||||
}: InjectedDependencies) {
|
||||
this.eventBusService_ = eventBusService
|
||||
this.searchService_ = searchService
|
||||
this.productService_ = productService
|
||||
this.featureFlagRouter_ = featureFlagRouter
|
||||
|
||||
this.eventBusService_.subscribe(SEARCH_INDEX_EVENT, this.indexDocuments)
|
||||
}
|
||||
@@ -54,36 +60,27 @@ class SearchIndexingSubscriber {
|
||||
lastSeenId: string,
|
||||
take: number
|
||||
): Promise<Product[]> {
|
||||
const relations = [
|
||||
"variants",
|
||||
"tags",
|
||||
"type",
|
||||
"collection",
|
||||
"variants.prices",
|
||||
"images",
|
||||
"variants.options",
|
||||
"options",
|
||||
]
|
||||
|
||||
if (
|
||||
this.featureFlagRouter_.isFeatureEnabled(ProductCategoryFeatureFlag.key)
|
||||
) {
|
||||
relations.push("categories")
|
||||
}
|
||||
|
||||
return await this.productService_.list(
|
||||
{ id: { gt: lastSeenId } },
|
||||
{
|
||||
select: [
|
||||
"id",
|
||||
"title",
|
||||
"status",
|
||||
"subtitle",
|
||||
"description",
|
||||
"handle",
|
||||
"is_giftcard",
|
||||
"discountable",
|
||||
"thumbnail",
|
||||
"profile_id",
|
||||
"collection_id",
|
||||
"type_id",
|
||||
"origin_country",
|
||||
"created_at",
|
||||
"updated_at",
|
||||
],
|
||||
relations: [
|
||||
"variants",
|
||||
"tags",
|
||||
"type",
|
||||
"collection",
|
||||
"variants.prices",
|
||||
"images",
|
||||
"variants.options",
|
||||
"options",
|
||||
],
|
||||
relations,
|
||||
take: take,
|
||||
order: { id: "ASC" },
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user