Giter VIP home page Giter VIP logo

pg-search-sequelize-example's Introduction

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.

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:

./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.

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

pg-search-sequelize-example's People

Contributors

mujz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

pg-search-sequelize-example's Issues

trying to learn usage

I am trying to incorporate this into a project. I set up my materialized view as in this example and included the corresponding code needed in my db index.js file, but I am getting this error when trying to test the search function:
SequelizeDatabaseError: function ts_rank(text, tsquery) does not exist
I do not know if this has something to do with not using the migration, although I am not seeing how that is used in this example.

Perhaps it is because my versions of Postgres and Sequelize are newer.

Thanks.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.