
Product
Introducing Socket Firewall Enterprise: Flexible, Configurable Protection for Modern Package Ecosystems
Socket Firewall Enterprise is now available with flexible deployment, configurable policies, and expanded language support.
@pinelab/vendure-plugin-better-search
Advanced tools
Vendure plugin for better storefront search, without the need of external systems
This plugin offers more intuitive storefront search than Vendure's DefaultSearchPlugin before the need of an external platform like TypeSense or ElasticSearch.
Important! The scope of this plugin:
DefaultSearchPlugin, but rather offers an additional endpoint in the shop-api for searching. The admin will still use the DefaultSearchPlugin for searching.Features:
vendure-config.ts:import { BetterSearchPlugin } from '@pinelab/vendure-plugin-better-search';
...
plugins: [
BetterSearchPlugin,
],
betterSearch query. The very first time, this will throw an error, and it will start building the index in the background.query Search {
betterSearch(input: { term: "dumbbells" }) {
totalItems
items {
productId
slug
productName
productAsset {
id
preview
}
lowestPrice
lowestPriceWithTax
highestPrice
highestPriceWithTax
facetValueIds
collectionIds
collectionNames
}
}
}
⚠️ Set the env variable BETTER_SEARCH_INDEX_COLUMN_TYPE for your specific database! Without this, text is used as default, but this will be too small for most projects. Run a database migration after setting this env variable!
# For MySQL
BETTER_SEARCH_INDEX_COLUMN_TYPE=mediumblob
# For PostgreSQL
BETTER_SEARCH_INDEX_COLUMN_TYPE=bytea
Checkout this page on more information on the different column types: https://orkhan.gitbook.io/typeorm/docs/entities#column-types-for-mysql-mariadb
You can add custom fields by defining a custom mapToSearchDocument function together with a custom indexableFields object.
For example, we have a custom field keywords on our products, and we want to index it, and return it in the search results:
import {
BetterSearchResult,
defaultSearchConfig,
BetterSearchConfigInput,
} from '@pinelab/vendure-plugin-better-search';
// Define an interface for our custom search result
interface MySearchResult extends BetterSearchResult {
keywords: string[];
}
export const searchConfig: BetterSearchConfigInput<MySearchResult> = {
mapToSearchDocument: (product, collections) => {
// Use the default mapping to get the base document
const defaultDocument = defaultSearchConfig.mapToSearchDocument(
product,
collections
);
return {
...defaultDocument,
// Extend the base document with "keywords"
keywords: product.customFields.keywords,
};
},
indexableFields: {
...defaultSearchConfig.indexableFields,
// Add "keywords" to the index with a weight of 2,
keywords: {
weight: 2,
// Tell the GraphQL schema that "keywords" is a [String!]!
// If you do not specify the graphqlFieldType, the field will not be returned in the search results
graphqlFieldType: "[String!]!",
},
},
};
// Then in your vendure-config.ts, use the searchConfig:
plugins: [
BetterSearchPlugin.init({
searchConfig,
}),
],
Checkout the defaultSearchConfig.ts for the default weights of each field.
keywords to your products, and make the plugin index it. This is where you'd save keywords, synonyms, etc. This will drastically improve the search experience.debounceIndexRebuildMs to reduce the number of rebuilds. If that doesn't work, your dataset might be too large for this search.FAQs
Vendure plugin for better storefront search, without the need of external systems
We found that @pinelab/vendure-plugin-better-search demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Product
Socket Firewall Enterprise is now available with flexible deployment, configurable policies, and expanded language support.

Security News
Open source dashboard CNAPulse tracks CVE Numbering Authorities’ publishing activity, highlighting trends and transparency across the CVE ecosystem.

Product
Detect malware, unsafe data flows, and license issues in GitHub Actions with Socket’s new workflow scanning support.