如何将chinese_directory配置添加到thinking-sphinx配置中

时间:2014-06-20 05:39:52

标签: ruby-on-rails ruby thinking-sphinx

我使用思考-sphinx 3.1.1,我有一个修改过的sphinx版本支持中文字符搜索。它有一个特殊的配置项必须放入配置  chinese_dictionary:“/ usr / local / sphinx-for-chinese / etc / xdict”

我已将“chinese_dictionay”添加到thinking_sphinx.yml 这是我的配置:

thinking_sphinx.yml:

发展:    chinese_dictionary:“/ usr / local / sphinx-for-chinese / etc / xdict”   thread_stack:1M

当我在developers.sphinx.conf中生成只有thread_stack的配置时,chinese_directory没有。

我搜索了一个丑陋的解决方案,它必须手工编辑。首先生成配置,rake ts:configure,手动将chinese_dictionary放到developments.sphinx.conf,然后rake ts:index INDEX_ONLY = true,我不喜欢这种方式。

我认为它可以通过向rails initializers目录添加一个文件来修改思维 - sphinx gems。我看了thking-sphinx的宝石,但我无法理解如何修改

import:chinese_dictionary:“/ usr / local / sphinx-for-chinese / etc / xdict”必须在索引下,这是正确的配置:

index article_core
{
    type = plain
    path = ~Documents/Project/blog/db/sphinx/development/article_core
    docinfo = extern
    charset_type = utf-8
    source = article_core_0
    chinese_dictionary = /usr/local/sphinx-for-chinese/etc/xdict
}

index article
{
    type = distributed
    local = article_core
}

1 个答案:

答案 0 :(得分:0)

它不是特别优雅,但这应该可以解决问题(把它放在初始化器中):

module ChineseDirectoryAccessor
  attr_accessor :chinese_dictionary
end

Riddle::Configuration::Index.include ChineseDirectoryAccessor
Riddle::Configuration::RealtimeIndex.include ChineseDirectoryAccessor

Riddle::Configuration::IndexSettings.module_eval do
  singleton_class.send :alias_method, :old_settings, :settings

  def self.settings
    old_settings + [:chinese_dictionary]
  end
end

确保Riddle(用于Sphinx配置)知道新设置。