Skip to content

PostgreSQL full text search using Rails 3 scopes

License

Notifications You must be signed in to change notification settings

StrangeMood/pg_search_scope

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PG Search Scope

PostgreSQL full text search using Rails 3 scopes

Basic usage

Include gem pg_search_scope in your Gemfile

In model, use search_scope_for class method to create full text search scope.

Examples:

search_scope_for :name
-->
search_by_name("Ivan")

In migration, use add_fulltext_index / remove_fulltext_index the same way as add_index / remove_index

Advanced usage

You can set additional search options:

:as - Scope name

:normalization - Controls rank behaviour, see http://www.postgresql.org/docs/9.0/static/textsearch-controls.html#TEXTSEARCH-RANKING

:wildcard - Controls search words modification:
                 true - add :* to ends of each search word
                 false - do not modify search words
                 :last - add :* to end of last word

:operator - Boolean operator (:and or :or) which combines search query

:select_rank - Include rank in select statement, as {scope_name}_rank

:language - Search language, e.g. 'simple' (without magic), 'english'

:rank_function - Ranking function. Valid values  are  'ts_rank' and 'ts_rank_cd'

:rank_columns - If you want to sort table by rank only by specific fields - input column names here

If you use :language option, you need to use the same option for add_fulltext_index

Examples:

search_scope_for :name, :address,
                 :wildcard => :last
-->
search_by_name_and_address("Ivan, Aurora st.", :select_rank => true)

To do

...

Copyright

Copyright (c) 2011 Ivan Efremov, Ilia Ablamonov, Cloud Castle Inc. See LICENSE for details.

About

PostgreSQL full text search using Rails 3 scopes

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Ruby 100.0%