How to enable: tsearch dictionary for multi-threaded pg_search search?

I am adding pg_search to a Rails application. I follow the instructions on github and railscast , but I ran into a problem.

I am creating a multi-user search and I have a basic implementation. But I want to extend pg_seach to use its English dictionary.

I already have an initializer:

PgSearch.multisearch_options = { :using => [:tsearch,:trigram], :ignoring => :accents } 

So, from what I read, it seems that adding a voice recorder should be as simple as

 PgSearch.multisearch_options = { :using => [:tsearch => [:dictionary => "english"],:trigram], :ignoring => :accents } 

But when I start my server

 ...config/initializers/pg_search.rb:2: syntax error, unexpected ']', expecting tASSOC (SyntaxError) :using => [:tsearch => [:dictionary => "english"],:trigram], 

I tried replacing the square with curly braces and all the other syntax permutations that I can think of, but no luck.

What is the correct syntax here? And why are my attempts invalid since I followed the syntax for searching in scope?

+4
source share
1 answer

What you posted doesn't match Ruby syntax.

You want something like this:

 PgSearch.multisearch_options = { :using => { :tsearch => { :dictionary => "english" }, :trigram => {} }, :ignoring => :accents } 

The reason is that you have to use Hash if you want to have key-value pairs. Thus, pg_search allows you to use two syntaxes:

 :using => someArray # such as [:tsearch, :trigram] 

which means "use tsearch and the trigram, as with the default parameters"

or

 :using => someHash # such as {:tsearch => optionsHash1, :trigram => optionsHash2} 

which means "use tsearch with some options from options Hash1 and use a trigram with some options from OptionsHash2"

Let me know if anything I can do to clarify. This is pretty simple Ruby syntax, but I understand that the fact that pg_search accepts both formats can be confusing for those who are not familiar with them.

+10
source

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


All Articles