In Files

Parent

Class/Module Index [+]

Quicksearch

TokyoTyrant::RDBQRY

This class is a helper for the class “TokyoTyrant::RDBTBL”.%%

Constants

MSDIFF

set operation type: difference

MSISECT

set operation type: intersection

MSUNION

set operation type: union

QCFTSAND

query condition: full-text search with all tokens in

QCFTSEX

query condition: full-text search with the compound expression of

QCFTSOR

query condition: full-text search with at least one token in

QCFTSPH

query condition: full-text search with the phrase of

QCNEGATE

query condition: negation flag

QCNOIDX

query condition: no index flag

QCNUMBT

query condition: number is between two tokens of

QCNUMEQ

query condition: number is equal to

QCNUMGE

query condition: number is greater than or equal to

QCNUMGT

query condition: number is greater than

QCNUMLE

query condition: number is less than or equal to

QCNUMLT

query condition: number is less than

QCNUMOREQ

query condition: number is equal to at least one token in

QCSTRAND

query condition: string includes all tokens in

QCSTRBW

query condition: string begins with

QCSTREQ

query condition: string is equal to

QCSTREW

query condition: string ends with

QCSTRINC

query condition: string is included in

QCSTROR

query condition: string includes at least one token in

QCSTROREQ

query condition: string is equal to at least one token in

QCSTRRX

query condition: string matches regular expressions of

QONUMASC

order type: number ascending

QONUMDESC

order type: number descending

QOSTRASC

order type: string ascending

QOSTRDESC

order type: string descending

Public Class Methods

new(rdb) click to toggle source

Create a query object.%% `rdb’ specifies the remote database object.%% The return value is the new query object.%%

# File tokyotyrant.rb, line 1321
def initialize(rdb)
  raise ArgumentError if !rdb.is_a?(TokyoTyrant::RDBTBL)
  @rdb = rdb
  @args = [ "hint" ]
end

Public Instance Methods

addcond(name, op, expr) click to toggle source

Add a narrowing condition.%% `name’ specifies the name of a column. An empty string means the primary key.%% `op’ specifies an operation type: `TokyoTyrant::RDBQRY::QCSTREQ’ for string which is equal to the expression, `TokyoTyrant::RDBQRY::QCSTRINC’ for string which is included in the expression, `TokyoTyrant::RDBQRY::QCSTRBW’ for string which begins with the expression, `TokyoTyrant::RDBQRY::QCSTREW’ for string which ends with the expression, `TokyoTyrant::RDBQRY::QCSTRAND’ for string which includes all tokens in the expression, `TokyoTyrant::RDBQRY::QCSTROR’ for string which includes at least one token in the expression, `TokyoTyrant::RDBQRY::QCSTROREQ’ for string which is equal to at least one token in the expression, `TokyoTyrant::RDBQRY::QCSTRRX’ for string which matches regular expressions of the expression, `TokyoTyrant::RDBQRY::QCNUMEQ’ for number which is equal to the expression, `TokyoTyrant::RDBQRY::QCNUMGT’ for number which is greater than the expression, `TokyoTyrant::RDBQRY::QCNUMGE’ for number which is greater than or equal to the expression, `TokyoTyrant::RDBQRY::QCNUMLT’ for number which is less than the expression, `TokyoTyrant::RDBQRY::QCNUMLE’ for number which is less than or equal to the expression, `TokyoTyrant::RDBQRY::QCNUMBT’ for number which is between two tokens of the expression, `TokyoTyrant::RDBQRY::QCNUMOREQ’ for number which is equal to at least one token in the expression, `TokyoTyrant::RDBQRY::QCFTSPH’ for full-text search with the phrase of the expression, `TokyoTyrant::RDBQRY::QCFTSAND’ for full-text search with all tokens in the expression, `TokyoTyrant::RDBQRY::QCFTSOR’ for full-text search with at least one token in the expression, `TokyoTyrant::RDBQRY::QCFTSEX’ for full-text search with the compound expression. All operations can be flagged by bitwise-or: `TokyoTyrant::RDBQRY::QCNEGATE’ for negation, `TokyoTyrant::RDBQRY::QCNOIDX’ for using no index.%% `expr’ specifies an operand exression.%% The return value is always `nil’.%%

# File tokyotyrant.rb, line 1331
def addcond(name, op, expr)
  @args.push("addcond" + "\00"" + name + "\00"" + op.to_s + "\00"" + expr)
  return nil
end
hint() click to toggle source

Get the hint string.%% The return value is the hint string.%%

# File tokyotyrant.rb, line 1413
def hint()
  return @hint
end
metasearch(others, type = MSUNION) click to toggle source

Retrieve records with multiple query objects and get the set of the result.%% `others’ specifies an array of the query objects except for the self object.%% `type’ specifies a set operation type: `TokyoTyrant::RDBQRY::MSUNION’ for the union set, `TokyoTyrant::RDBQRY::MSISECT’ for the intersection set, `TokyoTyrant::RDBQRY::MSDIFF’ for the difference set. If it is not defined, `TokyoTyrant::RDBQRY::MSUNION’ is specified.%% The return value is an array of the primary keys of the corresponding records. This method does never fail. It returns an empty array even if no record corresponds.%% If the first query object has the order setting, the result array is sorted by the order.%%

# File tokyotyrant.rb, line 1421
def metasearch(others, type = MSUNION)
  raise ArgumentError if !others.is_a?(Array)
  args = @args.dup
  others.each do |other|
    next if !other.is_a?(RDBQRY)
    args.push("next")
    other._args.each do |arg|
      args.push(arg)
    end
  end
  args.push("mstype\00"" + type.to_s)
  @hint = ""
  rv = @rdb.misc("metasearch", args, RDB::MONOULOG)
  return Array::new if !rv
  _popmeta(rv)
  return rv
end
search() click to toggle source

Execute the search.%% The return value is an array of the primary keys of the corresponding records. This method does never fail. It returns an empty array even if no record corresponds.%%

# File tokyotyrant.rb, line 1353
def search()
  @hint = ""
  rv = @rdb.misc("search", @args, RDB::MONOULOG)
  return Array::new if !rv
  _popmeta(rv)
  return rv
end
searchcount() click to toggle source

Get the count of corresponding records.%% The return value is the count of corresponding records or 0 on failure.%%

# File tokyotyrant.rb, line 1402
def searchcount()
  args = @args.dup
  args.push("count")
  @hint = ""
  rv = @rdb.misc("search", args, RDB::MONOULOG)
  return 0 if !rv
  _popmeta(rv)
  return rv.size > 0 ? rv[0].to_i : 0
end
searchget(names = nil) click to toggle source

Get records corresponding to the search.%% `names’ specifies an array of column names to be fetched. An empty string means the primary key. If it is not defined, every column is fetched.%% The return value is an array of column hashes of the corresponding records. This method does never fail. It returns an empty list even if no record corresponds.%% Due to the protocol restriction, this method can not handle records with binary columns including the “0” chracter.%%

# File tokyotyrant.rb, line 1375
def searchget(names = nil)
  raise ArgumentError if names && !names.is_a?(Array)
  args = @args.dup
  if names
    args.push("get\00"" + names.join("\00""))
  else
    args.push("get")
  end
  @hint = ""
  rv = @rdb.misc("search", args, RDB::MONOULOG)
  return Array::new if !rv
  _popmeta(rv)
  for i in 0...rv.size
    cols = Hash::new
    cary = rv[i].split("\00"")
    cnum = cary.size - 1
    j = 0
    while j < cnum
      cols[cary[j]] = cary[j+1]
      j += 2
    end
    rv[i] = cols
  end
  return rv
end
searchout() click to toggle source

Remove each corresponding record.%% If successful, the return value is true, else, it is false.%%

# File tokyotyrant.rb, line 1362
def searchout()
  args = @args.dup
  args.push("out")
  @hint = ""
  rv = @rdb.misc("search", args, 0)
  return false if !rv
  _popmeta(rv)
  return true
end
setlimit(max = -1, skip = -1) click to toggle source

Set the maximum number of records of the result.%% `max’ specifies the maximum number of records of the result. If it is not defined or negative, no limit is specified.%% `skip’ specifies the maximum number of records of the result. If it is not defined or not more than 0, no record is skipped.%% The return value is always `nil’.%%

# File tokyotyrant.rb, line 1347
def setlimit(max = -1, skip = -1)
  @args.push("setlimit" + "\00"" + max.to_s + "\00"" + skip.to_s)
  return nil
end
setorder(name, type = QOSTRASC) click to toggle source

Set the order of the result.%% `name’ specifies the name of a column. An empty string means the primary key.%% `type’ specifies the order type: `TokyoTyrant::RDBQRY::QOSTRASC’ for string ascending, `TokyoTyrant::RDBQRY::QOSTRDESC’ for string descending, `TokyoTyrant::RDBQRY::QONUMASC’ for number ascending, `TokyoTyrant::RDBQRY::QONUMDESC’ for number descending. If it is not defined, `TokyoTyrant::RDBQRY::QOSTRASC’ is specified.%% The return value is always `nil’.%%

# File tokyotyrant.rb, line 1339
def setorder(name, type = QOSTRASC)
  @args.push("setorder" + "\00"" + name + "\00"" + type.to_s)
  return nil
end

Protected Instance Methods

_args() click to toggle source

Get the internal arguments.

# File tokyotyrant.rb, line 1443
def _args
  return @args
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.