UNPKG

@unchainedshop/plugins

Version:

Because of a Typescript issue with upstream "postfinancecheckout", the Postfinance plugin has been disabled from transpilation, import the source ts files from src and enable node_module tsc or copy over the src/payment/postfinance-checkout to your projec

71 lines 2.79 kB
import { FilterDirector, FilterAdapter } from '@unchainedshop/core'; const LocalSearch = { ...FilterAdapter, key: 'shop.unchained.filters.local-search', label: 'Simple Fulltext search with MongoDB', version: '1.0.0', orderIndex: 10, actions: (params) => { return { ...FilterAdapter.actions(params), searchProducts: async ({ productIds }) => { // Search Products const { queryString } = params.searchQuery; if (!queryString) return productIds; const selector = { $text: { $search: queryString }, }; if (productIds) { selector.productId = { $in: [...new Set(productIds)] }; } const products = await params.modules.products.texts.findTexts(selector, { projection: { productId: 1, }, }); return products.map(({ productId }) => productId); }, // eslint-disable-next-line searchAssortments: async ({ assortmentIds }) => { const { queryString } = params.searchQuery; if (!queryString) { return assortmentIds; } const selector = { $text: { $search: queryString }, }; if (assortmentIds) { selector.assortmentId = { $in: assortmentIds }; } const assortments = await params.modules.assortments.texts.findTexts(selector, { projection: { assortmentId: 1, }, }); return assortments.map(({ assortmentId }) => assortmentId); }, async transformFilterSelector(last) { const { queryString, filterIds, includeInactive } = params.searchQuery; if (queryString && !filterIds) { // Global search without assortment scope: // Return all filters const selector = { ...last }; if (selector?.key) { // Do not restrict to keys delete selector.key; } if (!includeInactive) { // Include only active filters selector.isActive = true; } return selector; } return last; }, }; }, }; export default LocalSearch; FilterDirector.registerAdapter(LocalSearch); //# sourceMappingURL=local-search.js.map