【发布时间】:2011-12-01 15:47:39
【问题描述】:
这是交易:我有一个包含大量数据库项目(通过 Sunspot 索引)的 RoR 应用程序,其中一些带有文件附件(通常是 PDF 和纯文本文件)。在全文搜索中包含这些文档内容的最简单方法是什么?
【问题讨论】:
标签: ruby-on-rails search activerecord full-text-search
这是交易:我有一个包含大量数据库项目(通过 Sunspot 索引)的 RoR 应用程序,其中一些带有文件附件(通常是 PDF 和纯文本文件)。在全文搜索中包含这些文档内容的最简单方法是什么?
【问题讨论】:
标签: ruby-on-rails search activerecord full-text-search
使用像 pdf-reader 这样的 PDF 阅读器 gem,并在 Sunspot 中对其进行索引。
class Item < ActiveRecord::Base
searchable if: proc{ |topic| topic.try(:price).try(:>,0) } do
text :attachment_text # index result returned from attachment() method
end
# getting text out of attachment
def attachment_text
# pseudo code of determining attachment format
case attachment.extension
when :pdf
# Use pdf-reader gem get all the text from all pages
when :txt
return open(attachment).read()
end
end
end
【讨论】: