feat(medusa-plugin-algolia): Revamp Algolia search plugin (#3510)
This commit is contained in:
1 parent
ef5ef9f5a2
commit
74bc4b16a0
43 files changed
+518
-454
No files matched your search
@@ -7,7 +7,6 @@ export * from "./notification-service"
|
||||
export * from "./payment-processor"
|
||||
export * from "./payment-service"
|
||||
export * from "./price-selection-strategy"
|
||||
export * from "./search-service"
|
||||
export * from "./services"
|
||||
export * from "./tax-calculation-strategy"
|
||||
export * from "./tax-service"
|
||||
|
||||
@@ -1,120 +0,0 @@
|
||||
import { SearchService } from "medusa-interfaces"
|
||||
|
||||
export interface ISearchService {
|
||||
options: Record<string, unknown>
|
||||
|
||||
/**
|
||||
* Used to create an index
|
||||
* @param indexName the index name
|
||||
* @param options the options
|
||||
* @return returns response from search engine provider
|
||||
*/
|
||||
createIndex(indexName: string, options: unknown): unknown
|
||||
|
||||
/**
|
||||
* Used to get an index
|
||||
* @param indexName - the index name.
|
||||
* @return returns response from search engine provider
|
||||
*/
|
||||
getIndex(indexName: string): unknown
|
||||
|
||||
/**
|
||||
* Used to index documents by the search engine provider
|
||||
* @param indexName the index name
|
||||
* @param documents documents array to be indexed
|
||||
* @param type of documents to be added (e.g: products, regions, orders, etc)
|
||||
* @return returns response from search engine provider
|
||||
*/
|
||||
addDocuments(indexName: string, documents: unknown, type: string): unknown
|
||||
|
||||
/**
|
||||
* Used to replace documents
|
||||
* @param indexName the index name.
|
||||
* @param documents array of document objects that will replace existing documents
|
||||
* @param type type of documents to be replaced (e.g: products, regions, orders, etc)
|
||||
* @return returns response from search engine provider
|
||||
*/
|
||||
replaceDocuments(indexName: string, documents: unknown, type: string): unknown
|
||||
|
||||
/**
|
||||
* Used to delete document
|
||||
* @param indexName the index name
|
||||
* @param document_id the id of the document
|
||||
* @return returns response from search engine provider
|
||||
*/
|
||||
deleteDocument(indexName: string, document_id: string | number): unknown
|
||||
|
||||
/**
|
||||
* Used to delete all documents
|
||||
* @param indexName the index name
|
||||
* @return returns response from search engine provider
|
||||
*/
|
||||
deleteAllDocuments(indexName: string): unknown
|
||||
|
||||
/**
|
||||
* Used to search for a document in an index
|
||||
* @param indexName the index name
|
||||
* @param query the search query
|
||||
* @param options
|
||||
* - any options passed to the request object other than the query and indexName
|
||||
* - additionalOptions contain any provider specific options
|
||||
* @return returns response from search engine provider
|
||||
*/
|
||||
search(indexName: string, query: string | null, options: unknown): unknown
|
||||
|
||||
/**
|
||||
* Used to update the settings of an index
|
||||
* @param indexName the index name
|
||||
* @param settings settings object
|
||||
* @return returns response from search engine provider
|
||||
*/
|
||||
updateSettings(indexName: string, settings: unknown): unknown
|
||||
}
|
||||
|
||||
export abstract class AbstractSearchService implements ISearchService {
|
||||
abstract readonly isDefault
|
||||
protected readonly options_: Record<string, unknown>
|
||||
|
||||
get options(): Record<string, unknown> {
|
||||
return this.options_
|
||||
}
|
||||
|
||||
protected constructor(container, options) {
|
||||
this.options_ = options
|
||||
}
|
||||
|
||||
abstract createIndex(indexName: string, options: unknown): unknown
|
||||
|
||||
abstract getIndex(indexName: string): unknown
|
||||
|
||||
abstract addDocuments(
|
||||
indexName: string,
|
||||
documents: unknown,
|
||||
type: string
|
||||
): unknown
|
||||
|
||||
abstract replaceDocuments(
|
||||
indexName: string,
|
||||
documents: unknown,
|
||||
type: string
|
||||
): unknown
|
||||
|
||||
abstract deleteDocument(
|
||||
indexName: string,
|
||||
document_id: string | number
|
||||
): unknown
|
||||
|
||||
abstract deleteAllDocuments(indexName: string): unknown
|
||||
|
||||
abstract search(
|
||||
indexName: string,
|
||||
query: string | null,
|
||||
options: unknown
|
||||
): unknown
|
||||
|
||||
abstract updateSettings(indexName: string, settings: unknown): unknown
|
||||
}
|
||||
|
||||
export function isSearchService(obj: unknown): boolean {
|
||||
return obj instanceof AbstractSearchService || obj instanceof SearchService
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
import { SearchUtils } from "@medusajs/utils"
|
||||
import { aliasTo, asFunction, asValue, Lifetime } from "awilix"
|
||||
import { Express } from "express"
|
||||
import fs from "fs"
|
||||
@@ -20,7 +21,6 @@ import {
|
||||
isFileService,
|
||||
isNotificationService,
|
||||
isPriceSelectionStrategy,
|
||||
isSearchService,
|
||||
isTaxCalculationStrategy,
|
||||
} from "../interfaces"
|
||||
import { MiddlewareService } from "../services"
|
||||
@@ -443,7 +443,7 @@ export async function registerServices(
|
||||
),
|
||||
[`fileService`]: aliasTo(name),
|
||||
})
|
||||
} else if (isSearchService(loaded.prototype)) {
|
||||
} else if (SearchUtils.isSearchService(loaded.prototype)) {
|
||||
// Add the service directly to the container in order to make simple
|
||||
// resolution if we already know which search provider we need to use
|
||||
container.register({
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { AbstractSearchService } from "../interfaces"
|
||||
import { AbstractSearchService } from "@medusajs/utils"
|
||||
import { EventBusService } from "../services"
|
||||
import { Logger, MedusaContainer } from "../types/global"
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { AbstractSearchService } from "@medusajs/utils"
|
||||
import { EntityManager } from "typeorm"
|
||||
import { AbstractSearchService } from "../interfaces/search-service"
|
||||
import { Logger } from "../types/global"
|
||||
|
||||
type InjectedDependencies = {
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import { EventBusTypes } from "@medusajs/types"
|
||||
import { IEventBusService, ISearchService } from "@medusajs/types"
|
||||
import { indexTypes } from "medusa-core-utils"
|
||||
import { ISearchService } from "../interfaces"
|
||||
import ProductCategoryFeatureFlag from "../loaders/feature-flags/product-categories"
|
||||
import { SEARCH_INDEX_EVENT } from "../loaders/search-index"
|
||||
import { Product } from "../models"
|
||||
@@ -8,14 +7,14 @@ import ProductService from "../services/product"
|
||||
import { FlagRouter } from "../utils/flag-router"
|
||||
|
||||
type InjectedDependencies = {
|
||||
eventBusService: EventBusTypes.IEventBusService
|
||||
eventBusService: IEventBusService
|
||||
searchService: ISearchService
|
||||
productService: ProductService
|
||||
featureFlagRouter: FlagRouter
|
||||
}
|
||||
|
||||
class SearchIndexingSubscriber {
|
||||
private readonly eventBusService_: EventBusTypes.IEventBusService
|
||||
private readonly eventBusService_: IEventBusService
|
||||
private readonly searchService_: ISearchService
|
||||
private readonly productService_: ProductService
|
||||
private readonly featureFlagRouter_: FlagRouter
|
||||
|
||||
Reference in new issue
Block a user