🚀 DAY 5 OF LAUNCH WEEK: Introducing Socket Firewall Enterprise.Learn more →
Socket
Book a DemoInstallSign in
Socket

@pinelab/vendure-plugin-better-search

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@pinelab/vendure-plugin-better-search

Vendure plugin for better storefront search, without the need of external systems

Source
npmnpm
Version
0.1.4
Version published
Weekly downloads
28
Maintainers
1
Weekly downloads
 
Created
Source

Vendure Better Search Plugin

Official documentation here

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:

  • Aims to provide better search experience for storefront users without adding any infrastructure complexity.
  • Aims to provide better customizability for the developers in the way products are indexed and searched.
  • Doesn't replace the DefaultSearchPlugin, but rather offers an additional endpoint in the shop-api for searching. The admin will still use the DefaultSearchPlugin for searching.
  • This plugin is meant for shops with up to ~10000 variants.

Features:

  • Search by term or multiple terms, no and/or logic or query syntax.
  • Fuzzy matching / type tolerance
  • Custom field indexation
  • Index field weighting
  • Filtering by facets (faceted search): Planned feature, not implemented yet.

Getting started

  • Add the plugin to your vendure-config.ts:
import { BetterSearchPlugin } from '@pinelab/vendure-plugin-better-search';

...
plugins: [
  BetterSearchPlugin,
],
  • Run a database migration
  • Start the server
  • Do a search via the new 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

Indexing custom fields

You can index custom fields of your products by defining a custom mapToSearchDocument function.

For example, we have a custom field keywords on our products, and we want to index it:

import { BetterSearchPlugin, defaultSearchConfig } from '@pinelab/vendure-plugin-better-search';

      BetterSearchPlugin.init({
        mapToSearchDocument: (product, collections) => {
            // Import the default mapping function to get a default search document
          const defaultDocument = defaultSearchConfig.mapToSearchDocument(
            product,
            collections
          );
          const keywords = product.customFields.keywords;
          return {
            ...defaultDocument,
            keywords,
          };
        },
        // Make sure to add `keywords` to the indexable fields, and give it a weight
        indexableFields: {
          ...defaultSearchConfig.indexableFields,
          facetValueNames: 2,
        },
      }),

By default, these fields are indexed with the following weights. Checkout the defaultSearchConfig.ts for more details.

  indexableFields: {
    name: 3,
    slug: 2,
    variantNames: 3,
    collectionNames: 1,
    skus: 2,
  },

FAQs

Package last updated on 30 May 2025

Did you know?

Socket

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.

Install

Related posts