Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Ruby
branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
lib
spec
.gitignore
Gemfile
LICENSE.txt WIP
README.md
Rakefile WIP
postgres-fulltext-search-helper.gemspec

README.md

PostgresFulltextSearchHelper

This is just a quick helper gem for Nulogy's extremely naive full text search powered autocomplete. It abstracts away a lot of the flexibility of the postgres full text search API in favour of a very simple API that fulfills our simple needs.

This gem can be used to sanitize user input for safe queries into postgres's tsquery language, and will generate somewhat predictable results. All characters that are meaningful to the tsquery language are simply filtered out and interpreted as a boolean '&', which we find to be effective enough for the purposes of autocomplete.

Installation

Add this line to your application's Gemfile:

gem 'postgres-fulltext-search-helper'

And then execute:

$ bundle

Or install it yourself as:

$ gem install postgres-fulltext-search-helper

Usage

PostgresFulltextSearchHelper.format_query_for_fulltext("my query") will return a string that is suitable for insertion into a tsquery string for postgres.

If you're using Active Record or another library that implements where on a scope in a similar manner to Active Record, you can pass the relevant scope, field name, and query into the search method, like this:

filtered_scope = PostgresFulltextSearchHelper.search(scope, "name", "jus fit")

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request
Something went wrong with that request. Please try again.