Module: Ion

Defined in:
lib/ion.rb,
lib/ion/indices.rb,
lib/ion/indices/sort.rb,
lib/ion/indices/text.rb,
lib/ion/indices/number.rb,
lib/ion/indices/metaphone.rb

Defined Under Namespace

Modules: Entity, Helpers, Indices, Stringer Classes: Config, Index, Options, Scope, Search

Constant Summary collapse

VERSION =
"0.0.1"
PREFIX =
File.join(File.dirname(__FILE__), 'ion')
DEFAULT_TTL =

How long until search keys expire.

30
InvalidIndexType =
Class.new(StandardError)
Error =
Class.new(StandardError)

Class Method Summary collapse

Class Method Details

.configObject

Returns the Redis instance that is being used by Ion.



28
29
30
# File 'lib/ion.rb', line 28

def self.config
  @config ||= Ion::Config.new
end

.connect(to) ⇒ Object

Connects to a certain Redis server.



41
42
43
# File 'lib/ion.rb', line 41

def self.connect(to)
  @redis = Redis.connect(to)
end

.expire(*keys) ⇒ Object

Makes a certain volatile key expire.



60
61
62
# File 'lib/ion.rb', line 60

def self.expire(*keys)
  keys.each { |k| redis.expire(k, DEFAULT_TTL)  if k.include?('~') }
end

.intersect(keys, options = {}) ⇒ Object

Finds the intersection in multiple set keys.



77
78
79
80
81
82
83
# File 'lib/ion.rb', line 77

def self.intersect(keys, options={})
  return keys.first  if keys.size == 1

  results = Ion.volatile_key
  results.zinterstore keys, options
  results
end

.keyObject

Returns the root key.



46
47
48
49
50
51
52
# File 'lib/ion.rb', line 46

def self.key
  @key ||= if @redis
    Nest.new('Ion', @redis)
  else
    Nest.new('Ion')
  end
end

.redisObject



36
37
38
# File 'lib/ion.rb', line 36

def self.redis
  @redis || key.redis
end

.union(keys, options = {}) ⇒ Object

Combines multiple set keys.



68
69
70
71
72
73
74
# File 'lib/ion.rb', line 68

def self.union(keys, options={})
  return keys.first  if keys.size == 1

  results = Ion.volatile_key
  results.zunionstore keys, options
  results
end

.versionObject



32
33
34
# File 'lib/ion.rb', line 32

def self.version
  VERSION
end

.volatile_keyObject

Returns a new temporary key.



55
56
57
# File 'lib/ion.rb', line 55

def self.volatile_key
  key['~'][rand.to_s]
end