【问题标题】:Thinking Sphinx - reindexing on a per-table basisThinking Sphinx - 基于每个表重新索引
【发布时间】:2023-12-24 08:04:01
【问题描述】:

在我的开发配置中重新索引 Thinking Sphinx 索引需要几个小时,主要是因为有几个 huge 表(我们没有使用增量更新)。即使我为另一个小得多的表更改索引,由于存在大表,重新索引也需要一个多小时。

有什么方法可以强制 TS 只重新索引 db 中的指定表?

【问题讨论】:

    标签: ruby-on-rails thinking-sphinx


    【解决方案1】:

    没有办法告诉 Thinking Sphinx 一次处理一个索引,但直接通过 Sphinx 的索引器工具肯定是可能的(而且不是特别困难)。

    indexer --config config/development.sphinx.conf model_core
    

    需要注意的几点:除非您为索引定义提供自定义名称,否则它将默认为模型名称、小写和下划线,并带有 _core 后缀。如果你有 delta 索引,它们会有一个 _delta 后缀。此外,如果 Sphinx 正在运行,请将 --rotate 标志添加到该调用中。

    您可以指定任意数量的索引。如果您想一次处理所有索引(就像 Thinking Sphinx 的 rake 任务一样),--all 将为您完成。

    顺便说一句 - 我们谈论了多少条记录?您的索引定义有多复杂?几个小时的索引处理根本不常见。您对 Sphinx 索引中引用的关联使用的任何外键列都有数据库索引吗?

    【讨论】:

      【解决方案2】:

      我为此编写了一个(相当愚蠢的)BASH 函数。请注意,它必须从项目的根目录运行。

      # "rebuild" one index at a time
      function rebuildts {
        echo "rake ts:stop" && rake ts:stop
        echo "rake ts:configure" && rake ts:configure
        echo "Runnning indexer"
        indexer --config config/development.sphinx.conf $1
        echo "rake ts:start" && rake ts:start
      }
      

      用法:rebuildts my_model_core

      【讨论】: