Sha256: a9c78455b65c5e595cabc4d35b7d31395f057ac2d6777ed87d98c5a26e22a8d2

Contents?: true

Size: 1.11 KB

Versions: 5

Compression:

Stored size: 1.11 KB

Contents

module DataMapper
  module Adapters
    class FerretAdapter::LocalIndex

      attr_accessor :uri

      def initialize(uri)
        @uri = uri
        @options = { :path => @uri.path, :key => [:id, :_type] }
        create_or_initialize_index
      end

      def add(doc)
        @index << doc
      end

      def delete(query)
        @index.query_delete(query)
      end

      def search(query, options = {})
        @index.search(query, options).hits.collect { |hit, score| @index[hit.doc] }
      end

      def [](id)
        @index[id]
      end

      private

      def create_or_initialize_index
        unless File.exists?(@uri.path + "segments")
          field_infos = ::Ferret::Index::FieldInfos.new(:store => :no)
          field_infos.add_field(:id, :index => :untokenized, :term_vector => :no, :store => :yes)
          field_infos.add_field(:_type, :index => :untokenized, :term_vector => :no, :store => :yes)
          @index = ::Ferret::Index::Index.new( @options.merge(:field_infos => field_infos) )
        else
          @index = ::Ferret::Index::Index.new( @options )
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
dm-ferret-adapter-0.9.10 lib/ferret_adapter/local_index.rb
dm-ferret-adapter-0.9.11 lib/ferret_adapter/local_index.rb
dm-ferret-adapter-0.9.7 lib/ferret_adapter/local_index.rb
dm-ferret-adapter-0.9.8 lib/ferret_adapter/local_index.rb
dm-ferret-adapter-0.9.9 lib/ferret_adapter/local_index.rb