【问题标题】:Document search in RoRRoR 中的文档搜索
【发布时间】:2011-12-01 15:47:39
【问题描述】:

这是交易:我有一个包含大量数据库项目(通过 Sunspot 索引)的 RoR 应用程序,其中一些带有文件附件(通常是 PDF 和纯文本文件)。在全文搜索中包含这些文档内容的最简单方法是什么?

【问题讨论】:

    标签: ruby-on-rails search activerecord full-text-search


    【解决方案1】:

    使用像 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
    

    【讨论】:

      猜你喜欢
      • 2012-09-20
      • 2015-07-20
      • 1970-01-01
      • 2013-12-17
      • 2011-11-04
      • 2017-07-11
      • 2023-03-04
      • 2015-06-01
      • 2018-06-01
      相关资源
      最近更新 更多