2

我是 Sunspot 的新手,基于他们的 wiki https://github.com/sunspot/sunspot

"If you are using Rails, objects are automatically indexed to Solr as a part of the save callbacks."

但这对我在对象上调用 save 时不起作用,我必须手动运行 Object.reindex 才能在搜索结果中找到记录。我错过了什么吗?

谢谢

控制台日志

SQL (0.6ms)  INSERT INTO "toons" ("author", "created_at", "flag_id", "icon_s3_path", "json", "name", "state", "toon_type", "updated_at", "user_id", "uuid", "view_count") VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12) RETURNING "id"  [["author", "2333333"], ["created_at", Thu, 15 Aug 2013 22:49:40 UTC +00:00], ["flag_id", nil], ["icon_s3_path", nil], ["json", "[json]"], ["name", "2222222"], ["state", "created"], ["toon_type", "animation"], ["updated_at", Thu, 15 Aug 2013 22:49:40 UTC +00:00], ["user_id", 2], ["uuid", "2111112222"], ["view_count", nil]]

SOLR Request (25.6ms)  [ path=#<RSolr::Client:0x007fc37bb71920> parameters={data: <?xml version="1.0" encoding="UTF-8"?><add><doc><field name="id">Toon 21</field><field name="type">Toon</field><field name="type">ActiveRecord::Base</field><field name="class_name">Toon</field><field name="created_at_d">2013-08-15T22:49:40Z</field><field name="name_text">2222222</field><field name="author_text">2333333</field></doc></add>, headers: {"Content-Type"=>"text/xml"}, method: post, params: {:wt=>:ruby}, query: wt=ruby, path: update, uri: http://localhost:8982/solr/update?wt=ruby, open_timeout: , read_timeout: , retry_503: , retry_after_limit: } ]

SOLR Request (2.9ms)  [ path=#<RSolr::Client:0x007fc37bb71920> parameters={data: <?xml version="1.0" encoding="UTF-8"?><add><doc><field name="id">Toon 21</field><field name="type">Toon</field><field name="type">ActiveRecord::Base</field><field name="class_name">Toon</field><field name="created_at_d">2013-08-15T22:49:40Z</field><field name="name_text">2222222</field><field name="author_text">2333333</field></doc></add>, headers: {"Content-Type"=>"text/xml"}, method: post, params: {:wt=>:ruby}, query: wt=ruby, path: update, uri: http://localhost:8982/solr/update?wt=ruby, open_timeout: , read_timeout: , retry_503: , retry_after_limit: } ]

(7.5ms)  COMMIT
4

2 回答 2

1

通过在 solrconfig.xml 中添加自动提交来修复

<autoCommit> 
  <maxDocs>10000</maxDocs>
  <maxTime>20000</maxTime>
</autoCommit>
于 2013-08-18T23:53:10.977 回答
0

您是否为 solr 执行过任何重新索引?每当您更改模型中的可搜索块时(包括首次创建它时),您需要调用

rake sunspot:reindex

然后它会问你“你确定”,并提到一些关于拥有大量数据可能需要很长时间的警告。回复“y”,它将根据 solr 架构和可搜索的块重新索引您的所有数据。之后,当您将数据添加到数据库时,它应该会自动建立索引。不过,请记住在更改可搜索块时使用 rake 命令。

于 2013-08-16T04:16:51.217 回答