Class: TokyoTyrant::RDBQRY

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

Constants

MSDIFF
2
MSISECT
1
MSUNION
0
QCFTSAND
16
QCFTSEX
18
QCFTSOR
17
QCFTSPH
15
QCNEGATE
1 << 24
QCNOIDX
1 << 25
QCNUMBT
13
QCNUMEQ
8
QCNUMGE
10
QCNUMGT
9
QCNUMLE
12
QCNUMLT
11
QCNUMOREQ
14
QCSTRAND
4
QCSTRBW
2
QCSTREQ
0
QCSTREW
3
QCSTRINC
1
QCSTROR
5
QCSTROREQ
6
QCSTRRX
7
QONUMASC
2
QONUMDESC
3
QOSTRASC
0
QOSTRDESC
1

Constructor Summary

public initialize(rdb)

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

Meta Tags

Raises:

[ArgumentError]
[View source]


1310
1311
1312
1313
1314
# File 'lib/tokyotyrant.rb', line 1310

def initialize(rdb)
  raise ArgumentError if !rdb.is_a?(TokyoTyrant::RDBTBL)
  @rdb = rdb
  @args = [ "hint" ]
end

Public Visibility

Public Instance Method Summary

#addcond(name, op, expr)

Add a narrowing condition.

#hint

Get the hint string.

#metasearch(others, type = MSUNION)

Retrieve records with multiple query objects and get the set of the result.

#search

Execute the search.

#searchcount

Get the count of corresponding records.

#searchget(names = nil)

Get records corresponding to the search.

#searchout

Remove each corresponding record.

#setlimit(max = -1, skip = -1)

Set the maximum number of records of the result.

#setorder(name, type = QOSTRASC)

Set the order of the result.

Public Instance Method Details

addcond

public addcond(name, op, expr)

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’.%%

[View source]


1320
1321
1322
1323
# File 'lib/tokyotyrant.rb', line 1320

def addcond(name, op, expr)
  @args.push("addcond" + "\0" + name + "\0" + op.to_s + "\0" + expr)
  return nil
end

hint

public hint

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

[View source]


1402
1403
1404
# File 'lib/tokyotyrant.rb', line 1402

def hint()
  return @hint
end

metasearch

public metasearch(others, type = MSUNION)

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.%%

Meta Tags

Raises:

[ArgumentError]
[View source]


1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
# File 'lib/tokyotyrant.rb', line 1410

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\0" + type.to_s)
  @hint = ""
  rv = @rdb.misc("metasearch", args, RDB::MONOULOG)
  return Array::new if !rv
  _popmeta(rv)
  return rv
end

search

public search

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.%%

[View source]


1342
1343
1344
1345
1346
1347
1348
# File 'lib/tokyotyrant.rb', line 1342

def search()
  @hint = ""
  rv = @rdb.misc("search", @args, RDB::MONOULOG)
  return Array::new if !rv
  _popmeta(rv)
  return rv
end

searchcount

public searchcount

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

[View source]


1391
1392
1393
1394
1395
1396
1397
1398
1399
# File 'lib/tokyotyrant.rb', line 1391

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

public searchget(names = nil)

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.%%

Meta Tags

Raises:

[ArgumentError]
[View source]


1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
# File 'lib/tokyotyrant.rb', line 1364

def searchget(names = nil)
  raise ArgumentError if names && !names.is_a?(Array)
  args = @args.dup
  if names
    args.push("get\0" + names.join("\0"))
  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("\0")
    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

public searchout

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

[View source]


1351
1352
1353
1354
1355
1356
1357
1358
1359
# File 'lib/tokyotyrant.rb', line 1351

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

public setlimit(max = -1, skip = -1)

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’.%%

[View source]


1336
1337
1338
1339
# File 'lib/tokyotyrant.rb', line 1336

def setlimit(max = -1, skip = -1)
  @args.push("setlimit" + "\0" + max.to_s + "\0" + skip.to_s)
  return nil
end

setorder

public setorder(name, type = QOSTRASC)

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’.%%

[View source]


1328
1329
1330
1331
# File 'lib/tokyotyrant.rb', line 1328

def setorder(name, type = QOSTRASC)
  @args.push("setorder" + "\0" + name + "\0" + type.to_s)
  return nil
end
Generated on Friday, September 18 2009 at 10:35:42 AM by YARD 0.2.3.5 (ruby-1.8.7).