'text...">

Fuzzy search in Texticle doesn't find anything in Ruby on Rails

I added the following to my gemfile:

gem 'texticle', "2.0", :require => 'texticle/rails' # search gem

      

Then I ran bundle install

and the package installed the gem

I am using Rails 3.1.0 and I am using Postgres database.

I check that I actually have the row that I am looking for in the database table:

ruby-1.9.2-p290 :004 > Hotel.first
Hotel Load (0.4ms)  SELECT "hotels".* FROM "hotels" LIMIT 1
 => #<Hotel id: 1, title: "Marriot Hotel", created_at: "2012-03-01 23:53:16", updated_at: "2012-03-01 23:53:16"> 

      

When I run `Hotel.search ('e')

ruby-1.9.2-p290 :005 > Hotel.search(:title => 'e')
Hotel Load (1.4ms)  SELECT "hotels".*, ts_rank(to_tsvector("hotels"."title"), to_tsquery('e')) AS "rank0.4785527956789428" FROM "hotels" WHERE (to_tsvector('english', "title") @@ to_tsquery('e')) ORDER BY "rank0.4785527956789428" DESC
 => [] 

      

I am not getting anything. I tried to run it Hotel.search('e')

and still nothing. If I try Hotel.search(:title => 'Marriot')

it then it works, but the reason I use Texticle is for fuzzy search.

Are there any other configurations missing?

thank

+3


source to share


2 answers


There are several things I would suggest checking:

  • Make sure the extension has been manually created for each database you use. I had no luck with "texticle: install_trigram". And if you are using Heroku there may be additional steps, especially if you are not migrating from your shared database.

  • Use the fuzzy_search method. There are 3 new methods in the latest version of Texticle; the original #search method has been deprecated.

To manually install an extension:

Local Dev / Test
psql -U &lt;username>

\l
\c db_development
CREATE EXTENSION pg_trgm;
\dx

\c db_test
CREATE EXTENSION pg_trgm;
\dx

\q

      

Integration / production of Heroku
heroku pg:psql

\dx

CREATE EXTENSION pg_trgm;
\dx

      

Further



PostgreSQL trigrams (fuzzy search)

Installing PostgreSQL Trigger

New text search methods (source)

+1


source


My understanding of how Texticle works is that it will do full text searches on your string columns, but not necessarily do fuzzy searches by default. If you look at the query it generates in Postgres, it looks for an "e" match, not any word that contains the letter "e".

You can read the Postgres docs here:

http://www.postgresql.org/docs/9.1/static/datatype-textsearch.html



However, I see support for prefix matching but not postfix matching in the docs, although I might be missing something.

What happens if you run Hotel.search ('Marr: *')?

0


source







All Articles