Sha256: 1cb12bbe45cf47634fdc40295a9637a06bbfb23e6136a484081265620c3bdbf6

Contents?: true

Size: 1.65 KB

Versions: 1

Compression:

Stored size: 1.65 KB

Contents

# 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*::*Base* is just concerned with creating index
#   files / redis entries and providing helper functions to e.g. check
#   the indexes.
#
# * *Index*::*Bundle*::*Base* is concerned with loading these index files into
#   memory / redis and looking up search data as fast as possible.
#
class Bundle

  attr_reader   :identifier,
                :files
  attr_accessor :inverted,
                :weights,
                :similarity,
                :configuration,
                :similarity_strategy

  delegate :clear,    :to => :inverted
  delegate :[], :[]=, :to => :configuration

  def initialize name, category, similarity_strategy
    @identifier    = "#{category.identifier}:#{name}"
    @files         = Backend::Files.new name, category

    @inverted      = {}
    @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

  def to_s
    "#{self.class}(#{identifier}, #{files})"
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
picky-2.7.0 lib/picky/bundle.rb