feat(medusa-plugin-algolia): Revamp Algolia search plugin (#3510)
This commit is contained in:
@@ -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
|
||||
}
|
||||
Reference in New Issue
Block a user