Postgres full text not matching partial words in Rails 3?

I just switched from MySQL to Postgres 9.0.3. I have a new application with little data (game data).

In any case, I cannot find partial words to search. Here is my search method:

def self.search(query)
  conditions = <<-EOS
    to_tsvector('english', title) @@ plainto_tsquery('english', ?)
  EOS

  find(:all, :conditions => [conditions, query])    
end

I'm sure I need a template, but I'm just learning Postgres.

When I search , I get the correct results: Shinobi

Alex Kidd in Shinobi World - Sega Home

Shinobi - Sega Master System

Shinobi - Nintendo Entertainment System

Cyber ​​Shinobi: Shinobi Part 2 - Sega Master System

But when I search , I get nothing? Shin

Thanks for any tips.

+3
source share
4 answers

, to_tsquery plainto_tsquery

http://www.postgresql.org/docs/current/static/textsearch-controls.html#TEXTSEARCH-PARSING-QUERIES

-

def self.search(query)
  conditions = <<-EOS
    to_tsvector('english', title) @@ to_tsquery('english', ?)
  EOS

  find(:all, :conditions => [conditions, query + ':*'])
end
+3

, .

find( :all, :conditions => [ 'name ~* ?', "SEARCH TERM" ] )
+2

Add a string *to the query string.

Find Shin*.

def self.search(query)
  conditions = <<-EOS
    to_tsvector('english', title) @@ plainto_tsquery('english', ?)
  EOS

  find(:all, :conditions => [conditions, query.concat("*")])    
end
0
source

Use prefix:

  pg_search_scope :search, against: [:name, :email],
    using: {tsearch: {prefix: true}}
0
source

Source: https://habr.com/ru/post/1794027/


All Articles