2015-07-20 45 views
0

在rails中使用Sunspot Solr。我的代碼看起來如下: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 
} 

任何幫助嗎?

回答

1

我猜字段「Title」的fieldType在schema.xml中被定義爲multivalued =「true」。

請將它設爲false,以便將其作爲字符串獲取。

+0

謝謝..問題解決了:) – smanvi12

+0

請幫我這個:http://stackoverflow.com/questions/31512210/indexing-using-two-tables-in-sunspot-solr-rails-4 – smanvi12