Class: Rack::Bug::SphinxPanel::Stats::Query

Inherits:
Object
  • Object
show all
Defined in:
lib/rack/bug/panels/sphinx_panel/stats.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(time, *command_args) ⇒ Query

Returns a new instance of Query.



10
11
12
13
14
15
16
17
# File 'lib/rack/bug/panels/sphinx_panel/stats.rb', line 10

def initialize(time, *command_args)
  @time = time
  if command_args.flatten.first == :search
    @command = "search: " + decode_message(command_args.first.flatten.last).collect{|k,v| "#{k} => #{v}"}.join(", ")
  else
    @command = command_args.flatten.first.to_s + ": No more info is available for this Sphinx request type"
  end
end

Instance Attribute Details

#commandObject (readonly)

Returns the value of attribute command.



8
9
10
# File 'lib/rack/bug/panels/sphinx_panel/stats.rb', line 8

def command
  @command
end

#timeObject (readonly)

Returns the value of attribute time.



7
8
9
# File 'lib/rack/bug/panels/sphinx_panel/stats.rb', line 7

def time
  @time
end

Instance Method Details

#consume_64intObject



53
54
55
56
57
# File 'lib/rack/bug/panels/sphinx_panel/stats.rb', line 53

def consume_64int
  i = @m.unpack("NN").first
  @m = @m.slice(8, @m.length - 8)
  i
end

#consume_intObject



47
48
49
50
51
# File 'lib/rack/bug/panels/sphinx_panel/stats.rb', line 47

def consume_int
  i = @m.unpack("N").first
  @m = @m.slice(4, @m.length - 4)
  i
end

#consume_stringObject



59
60
61
62
63
64
# File 'lib/rack/bug/panels/sphinx_panel/stats.rb', line 59

def consume_string
  len = consume_int
  s = @m.slice(0, len)
  @m = @m.slice(len, @m.length - len)
  s
end

#decode_message(m) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/rack/bug/panels/sphinx_panel/stats.rb', line 23

def decode_message(m)
  @m = m.clone
  params = ActiveSupport::OrderedHash.new

  params[:offset] = consume_int
  params[:limit] = consume_int
  params[:match_mode] = consume_int
  params[:rank_mode] = consume_int
  params[:sort_mode] = consume_int
  params[:sort_by] = consume_string
  params[:query] = consume_string
  wl = consume_int
  weights = []
  wl.times do weights << consume_int end
  params[:weights] = weights

  params[:index] = consume_string

  consume_string

  params[:id_range] = [consume_64int, consume_64int]
  params
end

#display_timeObject



19
20
21
# File 'lib/rack/bug/panels/sphinx_panel/stats.rb', line 19

def display_time
  "%.2fms" % time
end