【问题标题】:format of result in sunspot-solrsunspot-solr 中的结果格式
【发布时间】:2015-07-20 06:14:01
【问题描述】:

我在 Rails 中使用 Sunspot Solr。我的代码如下所示:

searchable do
  text :title, :stored => true
  string :id, :stored => true
  integer :status, :stored => true
end

在我的控制器中,执行搜索后,我将其存储在哈希中:

one_result= {:title => hit.stored(:title), :id => hit.stored(:id)}

现在当我执行puts one_result.inspect 时,我得到:

{"title": ["THIS IS TITLE"]
 "id":12345
}

问题是所有的文本字段都变成了数组[..]。我想将结果包含在 json 响应中。我希望它是:

{"title": "THIS IS TITLE"
 "id":12345
}

有什么帮助吗?

【问题讨论】:

    标签: ruby-on-rails solr sunspot-solr


    【解决方案1】:

    我猜“标题”字段的 fieldType 在 schema.xml 中定义为 multivalued="true"。

    请将其设为 false,以便将其作为字符串获取。

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-24
    • 1970-01-01
    • 1970-01-01
    • 2012-01-25
    相关资源
    最近更新 更多