Sha256: 854b0812c0af9428fe61a79e4a9262dd1a837306bbf57b5ac0c4c54520882f4c

Contents?: true

Size: 1.61 KB

Versions: 15

Compression:

Stored size: 1.61 KB

Contents

module Index # :nodoc:all
  # A Bundle is a number of indexes
  # per [index, category] combination.
  #
  # At most, there are three indexes:
  # * *core* index (always used)
  # * *weights* index (always used)
  # * *similarity* index (used with similarity)
  # 
  # In Picky, indexing is separated from the index
  # handling itself through a parallel structure.
  #
  # Both use methods provided by this base class, but
  # have very different goals:
  #
  # * *Indexing*::*Bundle* is just concerned with creating index files
  #   and providing helper functions to e.g. check the indexes.
  #
  # * *Index*::*Bundle* is concerned with loading these index files into
  #   memory and looking up search data as fast as possible.
  #
  class Bundle
    
    attr_reader   :identifier, :files
    attr_accessor :index, :weights, :similarity, :configuration, :similarity_strategy
    
    delegate :clear,    :to => :index
    delegate :[], :[]=, :to => :configuration
    
    def initialize name, configuration, similarity_strategy
      @identifier = "#{configuration.identifier} (#{name})"
      @files      = Files.new name, configuration
      
      @index         = {}
      @weights       = {}
      @similarity    = {}
      @configuration = {} # A hash with config options.
      
      @similarity_strategy = similarity_strategy
    end
    
    # Get a list of similar texts.
    #
    # Note: Does not return itself.
    #
    def similar text
      code = similarity_strategy.encoded text
      similar_codes = code && @similarity[code]
      similar_codes.delete text if similar_codes
      similar_codes || []
    end
    
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
picky-1.4.1 lib/picky/index/bundle.rb
picky-1.4.0 lib/picky/index/bundle.rb
picky-1.3.4 lib/picky/index/bundle.rb
picky-1.3.3 lib/picky/index/bundle.rb
picky-1.3.2 lib/picky/index/bundle.rb
picky-1.3.1 lib/picky/index/bundle.rb
picky-1.3.0 lib/picky/index/bundle.rb
picky-1.2.4 lib/picky/index/bundle.rb
picky-1.2.3 lib/picky/index/bundle.rb
picky-1.2.2 lib/picky/index/bundle.rb
picky-1.2.1 lib/picky/index/bundle.rb
picky-1.2.0 lib/picky/index/bundle.rb
picky-1.1.7 lib/picky/index/bundle.rb
picky-1.1.6 lib/picky/index/bundle.rb
picky-1.1.5 lib/picky/index/bundle.rb