我正在尝试使用Searchkick gem为MySQL数据库中的blob列提供全文搜索,该列具有以二进制格式存储的文本数据,当使用Zlib.inflate(model_column)函数时将变得可读。
有没有一种方法可以在将数据传递给searchkick之前执行数据转换?
将searchkick添加到我的应用程序中的其他模型中是可行的,只有在索引blob列时,我才会得到这个错误
Events.first.reindex
Events Load (0.5ms) SELECT `events`.* FROM `events` LIMIT 1
Events Store (3.4ms) {"id":"","exception":["Encoding::UndefinedConversionError","\"\\x9C\" from ASCII-8BIT to UTF-8"]}
Encoding::UndefinedConversionError: "\x9C" from ASCII-8BIT to UTF-8发布于 2016-04-13 00:12:30
您可以使用search_data方法控制对哪些数据进行索引。更改此方法后调用Model.reindex。例如:
class Event < ActiveRecord::Base
belongs_to :user
def search_data
{
blob: Zlib.inflate(model_column)
# ...
}
end
endhttps://stackoverflow.com/questions/36572939
复制相似问题