Sha256: 3f476e6257a4435d7b08a97c454dd27a70e4820d3f6da6fdd528e4d5a1fae244

Contents?: true

Size: 1.32 KB

Versions: 827

Compression:

Stored size: 1.32 KB

Contents

module TSV
  class << self
    attr_accessor :field_index_dir
    def field_index_dir
      @field_index_dir ||= Rbbt.var.cache.field_indices
    end
  end

  attr_accessor :field_indices


  def field_index(field)
    @field_indices ||= {}
    @field_indices[field] ||= Persist.persist_tsv(self, filename, {:field => field}, :prefix => "FieldIndex", :dir => TSV.field_index_dir, :persist => true, :serializer => :list, :engine => "BDB" ) do |data|
      tsv = {}
      case type 
      when :single, :list
        through :key, [field] do |key, values|
          value = values.first
          tsv[value] ||= []
          tsv[value] << key
        end
      else
        through :key, [field] do |key, values|
          values.first.each do |value|
            tsv[value] ||= []
            tsv[value] << key
          end
        end
      end

      tsv.each do |v,keys|
        data[v] = keys.sort
      end

      data
    end
  end

  def field_index_select(matches)
    final = nil
    matches.each do |field,values|
      i = field_index(field)

      if Array === values
        keys = values.inject([]){|acc,value| m = i[value]; acc = m.nil? ? acc : Misc.merge_sorted_arrays( acc, m) }
      else
        keys = i[values] || []
      end

      final = final.nil? ? keys : Misc.intersect_sorted_arrays(final, keys)
    end
    final
  end
end

Version data entries

827 entries across 827 versions & 1 rubygems

Version Path
rbbt-util-5.44.1 lib/rbbt/tsv/field_index.rb
rbbt-util-5.43.0 lib/rbbt/tsv/field_index.rb
rbbt-util-5.42.0 lib/rbbt/tsv/field_index.rb
rbbt-util-5.41.1 lib/rbbt/tsv/field_index.rb
rbbt-util-5.41.0 lib/rbbt/tsv/field_index.rb
rbbt-util-5.40.5 lib/rbbt/tsv/field_index.rb
rbbt-util-5.40.4 lib/rbbt/tsv/field_index.rb
rbbt-util-5.40.3 lib/rbbt/tsv/field_index.rb
rbbt-util-5.40.0 lib/rbbt/tsv/field_index.rb
rbbt-util-5.39.0 lib/rbbt/tsv/field_index.rb
rbbt-util-5.38.1 lib/rbbt/tsv/field_index.rb
rbbt-util-5.38.0 lib/rbbt/tsv/field_index.rb
rbbt-util-5.37.16 lib/rbbt/tsv/field_index.rb
rbbt-util-5.37.15 lib/rbbt/tsv/field_index.rb
rbbt-util-5.37.14 lib/rbbt/tsv/field_index.rb
rbbt-util-5.37.13 lib/rbbt/tsv/field_index.rb
rbbt-util-5.37.12 lib/rbbt/tsv/field_index.rb
rbbt-util-5.37.11 lib/rbbt/tsv/field_index.rb
rbbt-util-5.37.10 lib/rbbt/tsv/field_index.rb
rbbt-util-5.37.9 lib/rbbt/tsv/field_index.rb