https://github.com/mujz/pg-search-sequelize-example
An example use case of pg-search-sequelize node library
https://github.com/mujz/pg-search-sequelize-example
database database-search fast full-text full-text-search materialized materialized-view materialized-views node nodejs postgres postgresql search search-algorithm sequelize sequelizejs view
Last synced: 2 months ago
JSON representation
An example use case of pg-search-sequelize node library
- Host: GitHub
- URL: https://github.com/mujz/pg-search-sequelize-example
- Owner: mujz
- License: mit
- Created: 2017-03-06T05:52:53.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2017-03-15T06:42:50.000Z (over 8 years ago)
- Last Synced: 2025-03-26T08:07:02.834Z (3 months ago)
- Topics: database, database-search, fast, full-text, full-text-search, materialized, materialized-view, materialized-views, node, nodejs, postgres, postgresql, search, search-algorithm, sequelize, sequelizejs, view
- Language: JavaScript
- Homepage: https://github.com/mujz/pg-search-sequelize
- Size: 13.7 KB
- Stars: 10
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# PG Search Sequelize - Example
Demonstration of how to use the `pg-search-sequelize` package to search a database of films and actors.
# Demo
Try out this example's demo [here](https://mujz.ca/project/pg-search).
# Run it locally
Prerequisites: Docker. If you don't want to use Docker, you'll need to have Postgres and Node.js 6.0.0 or above installed.
To start the server and database with docker, run:
```js
./init.sh
```That's it. Now you can open your browser and navigate to `http://localhost:3000/`.
Test searching by navigating to `http://localhost:3000/film/x-men`. To filter your results by release year, modify your query to `http://localhost:3000/film/x-men releaseYear:2003`. Note that we did not hard code the release year filter; it is automatically provided by the `pg-search-sequelize` package.
# How It Works
Our database is very simple; we only have 3 tables: `film`, `actor`, and `film_actor`. Using `pg-search-sequelize`, we create a materialized view from the film and actor data. We give the film names the highest weight, details and cast get a lower weight, and the rest of the details follow in order. The weighting system allows our search results to be sorted by relevance depending on how we set it up. Because we gave movie names a higher order than cast names, a search query of "Washington" would yield a result of the movie "Washington Heights" before "Man on Fire," since the first has the search query in the movie name while the second has it in the movie's cast.
We then define our materialized view model in `/models` and register it with `pg-search-sequelize` so that we get the search functionality.
Finally, we expose two API `/film/:query` and we start the express server on port `3000`.
# Next Steps
If you are interested in using this package in your projects, head on over to [pg-search-sequelize](https://github.com/mujz/pg-search-sequelize).
If there's anything you didn't like, or if you have any comments or suggestions, please do submit them in the issues section of [pg-search-sequelize](https://github.com/mujz/pg-search-sequelize)