Sha256: 85a37c4bfd4a9385364e956150b704fbada5bf2f2c5f352a3a751d2684533d84
Contents?: true
Size: 1.62 KB
Versions: 1
Compression:
Stored size: 1.62 KB
Contents
# Polysearch #### Simplified polymorphic full text + similarity search based on postgres ## Requirements - Postgresql >= 11 - Rails >= 6.0 ## Usage 1. Add the gem to your project ```sh bundle add polysearch ``` 1. Run the generator ```sh bundle exec rails g polysearch:migration ``` You can also specify a datatype that your app uses for primary keys (default is `bigint`). For example, if your application uses `uuid` primary keys, you install the migration like this. ```sh bundle exec rails g polysearch:migration uuid ``` 1. Migrate the database ```sh bundle exec rails db:migrate ``` 1. Update the model(s) you'd like to search ```ruby class User < ApplicationRecord include Polysearch::Searchable after_save_commit :update_polysearch def to_tsvectors [] .then { |list| list << make_tsvector(first_name, weight: "A") } .then { |list| list << make_tsvector(last_name, weight: "A") } .then { |list| list << make_tsvector(email, weight: "B") } end end ``` 1. Start searching ``` User.create first_name: "Nate", last_name: "Hopkins", email: "nhopkins@mailinator.com" User.polysearch("nate") User.polysearch("ntae") # misspellings also return results User.polysearch("nate").where(created_at: 1.day.ago..Current.time) # active record chaining User.polysearch("nate").order(created_at: :desc) # chain additional ordering after the polysearch scope ``` ## License The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
polysearch-0.1.0 | README.md |