如何为pg_search多重搜索启用:tsearch字典? [英] How to enable :tsearch dictionary for pg_search multi-search?

查看:115
本文介绍了如何为pg_search多重搜索启用:tsearch字典?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将pg_search添加到Rails应用程序中.我正在按照github和此 railscast 上的说明进行操作,但是我遇到了一个问题.

I'm adding pg_search into a Rails app. I'm following the instructions on github and this railscast, but I've run into a problem.

我正在设置一个多模型搜索,并且有一个基本的实现工作.但我想扩展pg_seach以使用其英语词典.

I'm setting up a multi model search, and I have a basic implementation working. 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've read, it looks like adding the dictioary should be as simple as

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

但是当我启动服务器时

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

我尝试用方括号替换大括号,以及我能想到的所有其他语法排列,但是没有运气.

I've tried swapping square for curly brackets, and all the other syntax permutations I can think of, but no luck.

这里的正确语法是什么?为什么我的尝试无效,因为我遵循了范围搜索的语法?

What is the correct syntax here? And why aren't my attempts valid, as I've followed the syntax for scoped searches?

推荐答案

您发布的内容不是有效的Ruby语法.

What you posted is not valid Ruby syntax.

您想要这样的东西:

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

原因是,如果要具有键值对,则必须使用哈希.因此,本质上pg_search允许2种语法:

The reason is that you must use a Hash if you want to have key-value pairs. So essentially, pg_search allows 2 syntaxes:

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

意思是使用tsearch和trigram,它们都具有默认选项"

which means "use tsearch and trigram, both with the default options"

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

这意味着将tsearch与optionsHash1中的某些选项一起使用,并将trigram与optionsHash2中的某些选项一起使用"

which means "use tsearch with some options from optionsHash1, and use trigram with some options from OptionsHash2"

让我知道我是否可以做任何澄清的事情.这是非常基本的Ruby语法,但我知道pg_search接受两种格式的事实可能会使不熟悉的人感到困惑.

Let me know if there's anything I can do to clarify. It's pretty basic Ruby syntax, but I understand that the fact that pg_search accepts both formats can be confusing to those who aren't as familiar.

这篇关于如何为pg_search多重搜索启用:tsearch字典?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆