Sha256: 75a433850f1e0f8a2de41cacbc6f782a4d801e913efc9bb58cb7475a9633ba15

Contents?: true

Size: 1.11 KB

Versions: 1

Compression:

Stored size: 1.11 KB

Contents

module Sunspot

  class RichDocument < RSolr::Xml::Document
    include Enumerable

    def contains_attachment?
      @fields.each do |field|
        if field.name.to_s.include?("_attachment") && field.value.present?
          return true
        end
      end
      return false
    end

    def add(connection)
      params = {
        :wt => :ruby
      }

      data = nil

      @fields.each do |f|
        if f.name.to_s.include?("_attachment") and f.value.present?
          params['fmap.content']       = f.name
          params['stream.file']        = f.value.path
          params['stream.contentType'] = f.value.mime_type
        else
          param_name = "literal.#{f.name.to_s}"
          params[param_name] = [] unless params.has_key?(param_name)
          params[param_name] << f.value
        end
        if f.attrs[:boost]
          params["boost.#{f.name.to_s}"] = f.attrs[:boost]
        end
      end

      connection.send_and_receive('update/extract',
        { :method => :post,
          :params => params,
          :data => data,
          :headers => {"Content-Type" => ""}
        })
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
refinerycms-solr-1.0.9 lib/refinery/sunspot/rich_document.rb