knex-full-text-search-plugin
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

Knex Full-text Search Plugin

A Knex plugin for easy Full-text Search queries in Postgres.

Get Started

npm install knex-full-text-search-plugin
# OR
yarn add knex-full-text-search-plugin

Once installed, add the plugin to your Knex instance:

import Knex from 'knex';
import KnexFullTextSearchPlugin from 'knex-full-text-search-plugin';

export const db = Knex(config);

// Simply call the plugin with your Knex instance
KnexFullTextSearchPlugin(db);

Methods

selectWebSearchRank

Add a column with a rank/score for the given query.

The column alias defaults to rank.

The rank/score is calculated using the Postgres function ts_rank.

const results = await db('products')
    .select('id', 'name')
    .selectWebSearchRank('description', 'Shoes')
    .whereWebSearch('description', 'Shoes')
    .orderBy('rank', 'desc');

whereWebSearch

Add a WHERE clause to your query to filter by the given query.

Used in conjunction with selectWebSearchRank to compute a rank to order the results.

Note: Intelligently handles undefined input by returning the query builder unmodified.

const results = await db('products')
  .select('id', 'name')
  .selectWebSearchRank('description', 'Shoes')
  .whereWebSearch('description', 'Shoes')
  .orderBy('rank', 'desc');

Package Sidebar

Install

npm i knex-full-text-search-plugin

Weekly Downloads

119

Version

1.0.0

License

MIT

Unpacked Size

12.8 kB

Total Files

7

Last publish

Collaborators

  • justsml