【发布时间】:2017-04-26 14:42:03
【问题描述】:
我正在使用 Sunspot Solr (2.2.7) 在我们的应用程序中搜索和索引 AR 模型,但我们在这里做的事情有点不同。实际的可索引内容存储在序列化字段中,我扩展了 Sunspot::Adapters::InstanceAdapter 和 Sunspot::Adapters::DataAccessor 类以支持我们的用例并注册了这些适配器。
我在 config/initializers/sunspot.rb 类中定义了可索引字段,示例配置如下所示
Sunspot.setup(Office) do
time :published_at, trie: true
integer :id
text :name
integer :region_id
boolean :is_active
text :address
text :city
text :postal_area
string :postal_code
string :abbreviation
integer :person_ids, multiple: true
string :supported_locales, multiple: true
string :slug
end
一切似乎都在进行开发和生产(Ubuntu 16.04 运行 Solr 6.4.2)。
当我需要向索引添加一个新字段并尝试将此更改用于生产时,就会出现我遇到的问题。当我将上述行添加到 Sunspot.setup 块时
integer :department_ids, multiple: true
对于 Office 的设置和重新索引,它可以在我的本地计算机上运行,但是当我部署到生产环境时,新字段不会被拾取。
我已更新托管模式文件以包含新字段,但在我重新索引模型后,当我在查询工具中查询 Offices 时仍然看不到新字段。
返回 Office 的 JSON 响应示例如下所示:
{
"id":"Office 1",
"type":["Office", "Model"],
"class_name":["Office"],
"published_at_dt":"2017-03-22T23:32:22Z",
"id_i":1,
"search_name_s":"atlanta",
"region_id_i":2,
"is_active_b":true,
"postal_code_s":"30309",
"abbreviation_s":"ATL",
"person_ids_im":[513,
571,
1392,
1722,
1723],
"supported_locales_sm":["en"],
"slug_s":"houston",
"name_text":["Houston"],
"address_text":["1 Main Street<br/>Suite 1"],
"city_text":["Houston"],
"postal_area_text":["TX"],
"_version_":1565750688671072256},
}
我已将 log_level 设置为 DEBUG,但 SOLR 更新语句并没有告诉我太多信息。
SOLR Request (1.6ms) [ path=update parameters={} ]
我尝试在生产环境中进入 Rails 控制台,手动运行
Sunspot.remove_all!(Office)
然后运行我的索引任务,但该字段仍然没有被拾取。
我不确定如何进一步调试此问题。
我需要对托管模式进行更改是否存在问题(我的 conf 目录中没有 schema.xml,只有托管模式文件)。该字段在此处定义,并且对该字段运行查询有效,但返回 0 个结果。
我的初始化程序中的 Sunspot.setup 代码是否需要完全停止 Apache2 和 Sunspot 才能获取我的更改?我也尝试过,但没有看到变化。
或者问题在于我没有使用默认的 Rails AR 包含,因为我们的用例略有不同,并且缺少我需要在我的适配器/可索引类中实现的方法?
对此的任何帮助将不胜感激。
【问题讨论】:
标签: ruby-on-rails solr sunspot-solr