Class: Aerospike::Filter

Inherits:
Object
  • Object
show all
Defined in:
lib/aerospike/query/filter.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.Contains(bin_name, value, col_type) ⇒ Object



25
26
27
# File 'lib/aerospike/query/filter.rb', line 25

def self.Contains(bin_name, value, col_type)
  Filter.new(bin_name, value, value, nil, col_type)
end

.Equal(bin_name, value) ⇒ Object



21
22
23
# File 'lib/aerospike/query/filter.rb', line 21

def self.Equal(bin_name, value)
  Filter.new(bin_name, value, value)
end

.geoContainsGeoJSONPoint(bin_name, point, col_type = nil) ⇒ Object



43
44
45
46
# File 'lib/aerospike/query/filter.rb', line 43

def self.geoContainsGeoJSONPoint(bin_name, point, col_type = nil)
  point = point.to_json
  Filter.new(bin_name, point, point, ParticleType::GEOJSON, col_type)
end

.geoContainsPoint(bin_name, lon, lat, col_type = nil) ⇒ Object



48
49
50
51
# File 'lib/aerospike/query/filter.rb', line 48

def self.geoContainsPoint(bin_name, lon, lat, col_type = nil)
  point = GeoJSON.new({type: "Point", coordinates: [lon, lat]})
  geoContainsGeoJSONPoint(bin_name, point, col_type)
end

.geoWithinGeoJSONRegion(bin_name, region, col_type = nil) ⇒ Object



33
34
35
36
# File 'lib/aerospike/query/filter.rb', line 33

def self.geoWithinGeoJSONRegion(bin_name, region, col_type = nil)
  region = region.to_json
  Filter.new(bin_name, region, region, ParticleType::GEOJSON, col_type)
end

.geoWithinRadius(bin_name, lon, lat, radius_meter, col_type = nil) ⇒ Object



38
39
40
41
# File 'lib/aerospike/query/filter.rb', line 38

def self.geoWithinRadius(bin_name, lon, lat, radius_meter, col_type = nil)
  region = GeoJSON.new({type: "AeroCircle", coordinates: [[lon, lat], radius_meter]})
  geoWithinGeoJSONRegion(bin_name, region, col_type)
end

.Range(bin_name, from, to, col_type = nil) ⇒ Object



29
30
31
# File 'lib/aerospike/query/filter.rb', line 29

def self.Range(bin_name, from, to, col_type = nil)
  Filter.new(bin_name, from, to, nil, col_type)
end

Instance Method Details

#collection_typeObject

for internal use



81
82
83
84
85
86
87
88
89
# File 'lib/aerospike/query/filter.rb', line 81

def collection_type
  case @col_type
  when :default then 0
  when :list then 1
  when :mapkeys then 2
  when :mapvalues then 3
  else 0
  end
end

#estimate_sizeObject



53
54
55
# File 'lib/aerospike/query/filter.rb', line 53

def estimate_size
  return @name.bytesize + @begin.estimate_size + @end.estimate_size + 10
end

#to_sObject

Show the filter as String. This is util to show filters in logs.



94
95
96
97
# File 'lib/aerospike/query/filter.rb', line 94

def to_s
  return "#{@name} = #{@begin}" if @begin == @end
  "#{@name} = #{@begin} - #{@end}"
end

#write(buf, offset) ⇒ Object



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/aerospike/query/filter.rb', line 57

def write(buf, offset)
  # Write name.
  len = buf.write_binary(@name, offset+1)
  buf.write_byte(len, offset)
  offset += len + 1

  # Write particle type.
  buf.write_byte(@val_type, offset)
  offset+=1

  # Write filter begin.
  len = @begin.write(buf, offset+4)
  buf.write_int32(len, offset)
  offset += len + 4

  # Write filter end.
  len = @end.write(buf, offset+4)
  buf.write_int32(len, offset)
  offset += len + 4

  offset
end