add: abstract search functionality to core + adjust meilisearch-plugin

add SearchService interface to medusa-interfaces
add DefaultSearchService skeleton implementation to core
add search-index.js loader to core for indexing db documents
add SearchSubscriber to core
add loadToSearchEngine method in ProductService
switch order of loaders in core to load subscriptions AFTER plugins
adjust service and loader for medusa-plugin-meilisearch
This commit is contained in:
zakariaelas
2021-09-16 15:48:09 +01:00
parent 425c8a5e5d
commit 0fbde7c51f
24 changed files with 405 additions and 187 deletions
+1
View File
@@ -5,3 +5,4 @@ export { default as FulfillmentService } from "./fulfillment-service"
export { default as FileService } from "./file-service"
export { default as NotificationService } from "./notification-service"
export { default as OauthService } from "./oauth-service"
export { default as SearchService } from "./search-service"
@@ -0,0 +1,93 @@
import { BaseService } from "medusa-interfaces"
/**
* The interface that all search services must implement.
* @interface
*/
class SearchService extends BaseService {
constructor() {
super()
}
/**
* Used to create an index
* @param indexName {string} - the index name.
* @param [options] {string} - the index name.
* @return {Promise<{object}>} - returns response from search engine provider
*/
createIndex(indexName, options) {
throw Error("createIndex must be overridden by a child class")
}
/**
* Used to get an index
* @param indexName {string} - the index name.
* @return {Promise<{object}>} - returns response from search engine provider
*/
getIndex(indexName) {
throw Error("getIndex must be overridden by a child class")
}
/**
* Used to index documents by the search engine provider.
* @param indexName {string} - the index name.
* @param documents {Array.<Object>} - documents array to be indexed
* @return {Promise<{object}>} - returns response from search engine provider
*/
addDocuments(indexName, documents) {
throw Error("addDocuments must be overridden by a child class")
}
/**
* Used to replace documents
* @param indexName {string} - the index name.
* @param documents {Object} - array of document objects that will replace existing documents
* @return {Promise<{object}>} - returns response from search engine provider
*/
replaceDocuments(indexName, documents) {
throw Error("updateDocument must be overridden by a child class")
}
/**
* Used to delete document
* @param indexName {string} - the index name.
* @param document_id {string} - the id of the document.
* @return {Promise<{object}>} - returns response from search engine provider
*/
deleteDocument(indexName, document_id) {
throw Error("deleteDocument must be overridden by a child class")
}
/**
* Used to delete all documents
* @param indexName {string} - the index name.
* @return {Promise<{object}>} - returns response from search engine provider
*/
deleteAllDocuments(indexName) {
throw Error("deleteAllDocuments must be overridden by a child class")
}
/**
* Used to search for a document in an index
* @param indexName {string} - the index name.
* @param query {string} - the search query.
* @param options {object} - any options passed to the request object other than the query and indexName
* e.g. pagination options, filtering options, etc.
* @return {Promise<{object}>} - returns response from search engine provider
*/
search(indexName, query, options) {
throw Error("search must be overridden by a child class")
}
/**
* Used to update the settings of an index
* @param indexName {string} - the index name.
* @param settings {object} - settings object
* @return {Promise<{object}>} - returns response from search engine provider
*/
updateSettings(indexName, settings) {
throw Error("updateSettings must be overridden by a child class")
}
}
export default SearchService