Registry / database / pg-search-sequelize

pg-search-sequelize

JSON →
library0.0.10jsnpmunverified

pg-search-sequelize (v0.0.10) provides PostgreSQL full-text search in Node.js using Sequelize as the ORM. It automatically creates materialized views that combine searchable fields into ts_vector columns and adds `searchByText`, `search`, and `refresh` class methods to your models. Supports weighted search, filtering, ordering, and inclusion of associated model fields. The package is stable but has not been updated frequently; it requires Sequelize v4 (v5+ compatibility is unclear). Use it if you need simple, model-centric full-text search without raw queries, but be aware of limited maintenance and potential migration issues with newer Sequelize versions.

npm install pg-search-sequelize
INSTALL
IMPORT
SIG · PG-SEARCH-SEQUELIZ
P
pg-search-sequelize
databasejavascriptv0.0.10
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

SearchModel
✓ const SearchModel = require('pg-search-sequelize'); MyModel = new SearchModel(MyModel);
✗ import SearchModel from 'pg-search-sequelize';
This library uses CommonJS and does not support ESM imports. Must use require and then wrap your Sequelize model instance with new SearchModel().
searchByText
✓ const results = await MyModel.searchByText('query');
✗ const results = MyModel.searchByText('query');
searchByText is an async class method added to your model after wrapping with SearchModel. It must be called with await or .then().
createMaterializedView
✓ const { createMaterializedView } = require('pg-search-sequelize'); await createMaterializedView('view_name', Model, { fields: {...} });
✗ import { createMaterializedView } from 'pg-search-sequelize';
createMaterializedView is a named export from the same package, but must be destructured from require in CommonJS. It is a separate function from the SearchModel class.

Sets up a Film model, wraps it with SearchModel, creates a materialized view with weighted fields, and performs a full-text search with ordering.

const Sequelize = require('sequelize'); const sequelize = new Sequelize(process.env.DATABASE_URL || 'postgres://user:pass@localhost:5432/mydb'); const Film = sequelize.define('Film', { name: Sequelize.STRING, description: Sequelize.TEXT, city: Sequelize.STRING, releaseDate: Sequelize.DATEONLY, rating: Sequelize.INTEGER }, { timestamps: false }); const SearchModel = require('pg-search-sequelize'); const SearchableFilm = new SearchModel(Film); // Create the materialized view (run once or as migration) const { createMaterializedView } = require('pg-search-sequelize'); await createMaterializedView('film_search', Film, { fields: ['name', 'description', 'city'], weights: { name: 'A', description: 'B', city: 'B' }, filterFields: ['rating', 'releaseDate'] }); // Now search async function search() { const results = await SearchableFilm.searchByText('Chicago order:releaseDate'); console.log(results); } search().catch(err => console.error(err));
Debug
Known issues
gotchaThe library only supports CommonJS (require) and does not expose ESM imports. Using 'import SearchModel from ...' will fail.
fix
Use const SearchModel = require('pg-search-sequelize');
affects: >=0.0.1
breakingSequelize v5+ may break due to internal changes (the library is built for Sequelize v4). Unclear if it works with v5/v6/v7.
fix
Pin sequelize to v4.x or test thoroughly with newer versions.
affects: >=0.0.1
gotchaThe materialized view must be created separately (e.g., via migrations) before using search; otherwise, searches will fail with a 'relation does not exist' error.
fix
Run createMaterializedView() or equivalent migration before searching.
affects: >=0.0.1
deprecatedThe library is not actively maintained; no updates since 2018. Issues and pull requests may go unaddressed.
fix
Consider using raw SQL with Sequelize's query method or migrate to Sequelize's built-in search (e.g., Op.like or full-text extensions).
affects: >=0.0.1
Errors
Common errors & fixes
Error: Cannot find module 'pg-search-sequelize'
Package not installed or misspelled in require/import.
fix
Run 'npm install pg-search-sequelize' and ensure the require path is correct.
TypeError: SearchModel is not a constructor
Using ESM import (import SearchModel from ...) instead of CommonJS require.
fix
Use 'const SearchModel = require('pg-search-sequelize');'.
relation "film_search" does not exist
Materialized view has not been created before running search.
fix
Call 'createMaterializedView()' as part of migration or setup script.
SequelizeDatabaseError: column "searchable" does not exist
The materialized view definition does not include a 'searchable' column (expected by the library).
fix
Ensure createMaterializedView is called correctly with fields and weights options; check that the view was created with the proper columns.
Upgrade
Version history
0.0.10latest on npm
Audit
Dependencies
sequelizerequiredRequired peer dependency for ORM functionality
pgrequiredRequired for PostgreSQL connection
Agent activity
12 hits · last 30 days
node
10
Resources
pg-search-sequelize — npm install pg-search-sequelize · libregistry