Sha256: 85339a4f9aadf104f8df5b22320672861212943adcaa0ef004881807374b6de8

Contents?: true

Size: 1.98 KB

Versions: 22

Compression:

Stored size: 1.98 KB

Contents

module Picky

  class Category
    
    class Picky::IdNotGivenException < StandardError; end

    # Removes an indexed object with the
    # given id.
    #
    def remove id
      id = id.send key_format
      exact.remove id
      partial.remove id
    end

    # Adds and indexes this category of the
    # given object.
    #
    def add object, where = :unshift
      add_text object.id, object.send(from), where
    end

    # Removes the object's id, and then
    # adds it again.
    #
    def replace object, where = :unshift
      remove object.id
      add object, where
    end
    
    # Replaces just part of the indexed data.
    #
    # Note: Takes a hash as opposed to the add/replace method.
    #
    def replace_from hash
      return unless text = hash[from] || hash[from.to_s]
      
      raise IdNotGivenException.new unless id = hash[:id] || hash['id']
      id = id.send key_format
      
      remove id
      add_text id, text
    end

    # Add at the end.
    #
    def << thing
      add thing, __method__
    end

    # Add at the beginning.
    #
    def unshift thing
      add thing, __method__
    end

    # For the given id, adds the list of
    # strings to the index for the given id.
    #
    def add_text id, text, where = :unshift
      # text = text.to_sym if @symbols # SYMBOLS.
      tokens, _ = tokenizer.tokenize text
      tokens.each { |text| add_tokenized_token id.send(key_format), text, where, false }
    end

    #
    #
    def add_tokenized_token id, text, where = :unshift, format = true
      return unless text

      id = id.send key_format if format
      # text = text.to_sym if @symbols # SYMBOLS.

      exact.add id, text, where
      partial.add_partialized id, text, where
    end

    # Clears the realtime mapping.
    #
    def clear_realtime
      exact.clear_realtime
      partial.clear_realtime
    end

    # Builds the realtime mapping.
    #
    def build_realtime_mapping
      exact.build_realtime
      partial.build_realtime
    end

  end

end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
picky-4.12.6 lib/picky/category_realtime.rb
picky-4.12.5 lib/picky/category_realtime.rb
picky-4.12.4 lib/picky/category_realtime.rb
picky-4.12.3 lib/picky/category_realtime.rb
picky-4.12.2 lib/picky/category_realtime.rb
picky-4.12.1 lib/picky/category_realtime.rb
picky-4.12.0 lib/picky/category_realtime.rb
picky-4.11.3 lib/picky/category_realtime.rb
picky-4.11.2 lib/picky/category_realtime.rb
picky-4.11.1 lib/picky/category_realtime.rb
picky-4.11.0 lib/picky/category_realtime.rb
picky-4.10.0 lib/picky/category_realtime.rb
picky-4.9.0 lib/picky/category_realtime.rb
picky-4.8.1 lib/picky/category_realtime.rb
picky-4.8.0 lib/picky/category_realtime.rb
picky-4.7.0 lib/picky/category_realtime.rb
picky-4.6.6 lib/picky/category_realtime.rb
picky-4.6.5 lib/picky/category_realtime.rb
picky-4.6.4 lib/picky/category_realtime.rb
picky-4.6.3 lib/picky/category_realtime.rb