ruby on rails - Textacular Fuzzy Search -


i trying implement the textacular gem in rails 4 app. basic , advanced search work fine, when try implement fuzzy search, encounter trouble.

installation instructions repository:

finally, #fuzzy_search method lets use postgres's trigram search funcionality.

in order use this, you'll need make sure database has pg_trgm module installed. on development machine, can require textacular/tasks , run

rake textacular:install_trigram

depending on production environment, might able use rake task, or might have manually run command. postgres 9.1 , above, you'll want run

create extension pg_trgm;


what i've tried

i tried running rake textacular:install_trigram , bundle exec rake textacular:install_trigram in root directory of app , message:

/usr/local/cellar/postgresql/9.2.4/share/postgresql/extension/pg_trgm.control rake aborted! pg::insufficientprivilege: error:  permission denied create extension "pg_trgm" hint:  must superuser create extension. : create extension pg_trgm; /users/ssapra/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/connection_adapters/postgresql/database_statements.rb:128:in `exec' /users/ssapra/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/connection_adapters/postgresql/database_statements.rb:128:in `block in execute' /users/ssapra/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/connection_adapters/abstract_adapter.rb:425:in `block in log' /users/ssapra/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.0.0/lib/active_support/notifications/instrumenter.rb:20:in `instrument' /users/ssapra/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/connection_adapters/abstract_adapter.rb:420:in `log' /users/ssapra/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/connection_adapters/postgresql/database_statements.rb:127:in `execute' /users/ssapra/.rvm/gems/ruby-2.0.0-p247/gems/textacular-3.1.0/lib/textacular/postgres_module_installer.rb:54:in `install_postgres_91_module' /users/ssapra/.rvm/gems/ruby-2.0.0-p247/gems/textacular-3.1.0/lib/textacular/postgres_module_installer.rb:7:in `install_module' /users/ssapra/.rvm/gems/ruby-2.0.0-p247/gems/textacular-3.1.0/lib/textacular/tasks.rb:14:in `block (2 levels) in <top (required)>' /users/ssapra/.rvm/gems/ruby-2.0.0-p247/bin/ruby_noexec_wrapper:14:in `eval' /users/ssapra/.rvm/gems/ruby-2.0.0-p247/bin/ruby_noexec_wrapper:14:in `<main>' tasks: top => textacular:install_trigram 

based on this, tried sudo rake textacular:install_trigram , got this:

cannot load such file -- bundler/setup /users/ssapra/sameet/programming/webdev/rails/myapp/config/boot.rb:4:in `<top (required)>' /users/ssapra/sameet/programming/webdev/rails/myapp/config/application.rb:1:in `<top (required)>' /users/ssapra/sameet/programming/webdev/rails/myapp/rakefile:4:in `<top (required)>' /users/ssapra/.rvm/gems/ruby-2.0.0-p247/bin/ruby_noexec_wrapper:14:in `eval' /users/ssapra/.rvm/gems/ruby-2.0.0-p247/bin/ruby_noexec_wrapper:14:in `<main>' (see full trace running task --trace) 

lastly, after reading for postgres 9.1 , above, tried running psql , create extension pg_trgm;. no errors (although anytime now, tell me exists). \quit , replace line of code work:

@search = content.advanced_search(params[:search].split(" ").join("|")).basic_search(params[:search]) 

with:

@search = content.fuzzy_search(title: params[:search]).fuzzy_search(text: params[:search]) 

or even:

 @search = content.fuzzy_search(params[:search]) 

and this:

pg::undefinedfunction: error:  operator not exist: character varying % unknown line 1: ...nt(*) "contents"  (("contents"."title" % 'inv')) ...                                                              ^ hint:  no operator matches given name , argument type(s). might need add explicit type casts. : select count(*) "contents"  (("contents"."title" % 'inv')) , (("contents"."text" % 'inv')) 

it gets stuck on first line:

-if @contents.empty?        %p="no results found for: #{@query}" -elsif !@query.empty?        %p="your search results for: #{@query}" 

contents controller

in contents_controller.rb: have these 3 additions:

require 'textacular' require 'textacular/tasks' activerecord::base.extend(textacular) 

i running postgres 9.2.4. ideas?


Comments

Popular posts from this blog

Detect support for Shoutcast ICY MP3 without navigator.userAgent in Firefox? -

web - SVG not rendering properly in Firefox -

java - JavaFX 2 slider labelFormatter not being used -