新手问题 [已解决] 根据 Sunspot 文档配置, 查询 boolean 字段时, 没有查询到任何匹配结果, google 无果, 求指教?

rina · 2016年02月29日 · 最后由 martin91 回复于 2016年03月04日 · 1867 次阅读

sunspot 文档:https://github.com/sunspot/sunspot 配置:

class Project < ActiveRecord::Base
  searchable do
   text :name, :oneword, :description
   integer :category_ids, multiple: true
   integer :city_ids, multiple: true
  boolean :published
 end
end

数据库数据:

 pry(main)> Project.all
  Project Load (2.5ms)  SELECT DISTINCT "projects".* FROM "projects"  WHERE "projects"."deleted_at" IS NULL
=> [#<Project id: 1, name: "baidu", oneword: "Summary", description: "adf", stage: nil, industry: nil, city: "深圳", published: true, created_at: "2016-02-29 03:04:01", updated_at: "2016-02-29 10:30:18", team_story: nil, link: "liuzhen.me", status: "approved", deleted_at: nil>,
 #<Project id: 2, name: "dd", oneword: "dd", description: "ddd", stage: nil, industry: nil, city: "dd", published: false, created_at: "2016-02-29 10:44:23", updated_at: "2016-02-29 10:44:23", team_story: nil, link: "liuzhen.me", status: "drafted", deleted_at: nil>]

执行查询:

 Sunspot.search(Project) do
   with(:published, true)
end.results
D, [2016-02-29T21:03:46.567622 #9580] DEBUG -- :   SOLR Request (43.9ms)  [ path=select parameters={fq: ["type:Project", "published_b:true"], start: 0, rows: 30, q: "*:*"} ]
=> []

先检查索引里的值是否正确。

rina 关闭了讨论。 01月03日 17:39
rina 重新开启了讨论。 03月17日 10:31
rina 关闭了讨论。 03月17日 10:31
需要 登录 后方可回复, 如果你还没有账号请 注册新账号