@haus-tech/elastic-extended-filters-plugin
v3.0.3
Published
Adds a filter to the ElasticSearch plugin to allow for NOT filters
Readme
name: elastic-filter-not-plugin title: Elastic Filter Not Plugin description: Vendure plugin that extends the filtering capabilities of your e-commerce platform by adding support for "NOT" filters in Elasticsearch queries. version: 3.0.0
Elastic Filter Not Plugin
The Elastic Filter Not Plugin is a Vendure plugin that extends the filtering capabilities of your e-commerce platform by adding support for "NOT" filters in Elasticsearch queries. This plugin is particularly useful for scenarios where you need to exclude specific products or collections from search results.
Functionality
This plugin enables the following features:
- Adds "NOT" filtering capabilities to Elasticsearch queries.
- Seamlessly integrates with Vendure's search functionality.
- Customizable and easy to configure.
Use Cases
The Elastic Filter Not Plugin is ideal for:
- Excluding specific products or collections from search results.
- Enhancing search functionality with advanced filtering options.
- E-commerce stores that require precise control over search results.
Installation
To install the Elastic Filter Not Plugin, follow these steps:
Install the plugin package:
yarn add @haus-tech/elastic-filter-not-pluginOr, if using npm:
npm install @haus-tech/elastic-filter-not-pluginAdd the plugin to your Vendure configuration in
vendure-config.ts:import { ElasticFilterNotPlugin } from '@haus-tech/elastic-filter-not-plugin'; export const config = { plugins: [ ElasticFilterNotPlugin, ], };Restart your Vendure server.
Usage
Admin Configuration
No additional configuration is required in the Admin UI. The plugin works seamlessly with Elasticsearch and extends the existing search functionality.
Shop API
The plugin extends the shop API to support "NOT" filters in search queries. For example, you can exclude products with specific attributes using the following GraphQL query:
query SearchProducts($input: SearchInput!) {
search(input: $input) {
items {
productId
productName
}
}
}Example SearchInput with a "NOT" filter applied to facetValueFilters:
{
"term": "shoes",
"facetValueFilters": [
{
"not": ["sports"]
}
]
}Example Integration
To use the "NOT" filter in your storefront, modify your search queries to include the not field in the facetValueFilters. For example:
fetch('/shop-api', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
query: `
query SearchProducts($input: SearchInput!) {
search(input: $input) {
items {
productId
productName
}
}
}
`,
variables: {
input: {
term: 'shoes',
facetValueFilters: [
{
not: ['sports'],
},
],
},
},
}),
})
.then((res) => res.json())
.then((data) => {
console.log(data);
});Testing
- Run
yarn testto execute the e2e tests. - Implement additional tests to cover your specific use cases.
Publishing to NPM
Make sure you are logged in to NPM.
Build the plugin:
yarn buildPublish the plugin:
yarn publish
Resources
- Vendure Plugin Documentation
- GraphQL Code Generator for generating TypeScript types for custom GraphQL types.
