In Files

Parent

Class Index [+]

Quicksearch

TokyoTyrant::RDBQRY

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

Constants

QCSTREQ

query condition: string is equal to

QCSTRINC

query condition: string is included in

QCSTRBW

query condition: string begins with

QCSTREW

query condition: string ends with

QCSTRAND

query condition: string includes all tokens 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

QCNUMEQ

query condition: number is equal to

QCNUMGT

query condition: number is greater than

QCNUMGE

query condition: number is greater than or equal to

QCNUMLT

query condition: number is less than

QCNUMLE

query condition: number is less than or equal to

QCNUMBT

query condition: number is between two tokens of

QCNUMOREQ

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

QCFTSPH

query condition: full-text search with the phrase of

QCFTSAND

query condition: full-text search with all tokens in

QCFTSOR

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

QCFTSEX

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

QCNEGATE

query condition: negation flag

QCNOIDX

query condition: no index flag

QOSTRASC

order type: string ascending

QOSTRDESC

order type: string descending

QONUMASC

order type: number ascending

QONUMDESC

order type: number descending

MSUNION

set operation type: union

MSISECT

set operation type: intersection

MSDIFF

set operation type: difference

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
1321:     def initialize(rdb)
1322:       raise ArgumentError if !rdb.is_a?(TokyoTyrant::RDBTBL)
1323:       @rdb = rdb
1324:       @args = [ "hint" ]
1325:     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
1331:     def addcond(name, op, expr)
1332:       @args.push("addcond" + "\00"" + name + "\00"" + op.to_s + "\00"" + expr)
1333:       return nil
1334:     end
hint() click to toggle source

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

      # File tokyotyrant.rb, line 1413
1413:     def hint()
1414:       return @hint
1415:     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
1421:     def metasearch(others, type = MSUNION)
1422:       raise ArgumentError if !others.is_a?(Array)
1423:       args = @args.dup
1424:       others.each do |other|
1425:         next if !other.is_a?(RDBQRY)
1426:         args.push("next")
1427:         other._args.each do |arg|
1428:           args.push(arg)
1429:         end
1430:       end
1431:       args.push("mstype\00"" + type.to_s)
1432:       @hint = ""
1433:       rv = @rdb.misc("metasearch", args, RDB::MONOULOG)
1434:       return Array::new if !rv
1435:       _popmeta(rv)
1436:       return rv
1437:     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
1353:     def search()
1354:       @hint = ""
1355:       rv = @rdb.misc("search", @args, RDB::MONOULOG)
1356:       return Array::new if !rv
1357:       _popmeta(rv)
1358:       return rv
1359:     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
1402:     def searchcount()
1403:       args = @args.dup
1404:       args.push("count")
1405:       @hint = ""
1406:       rv = @rdb.misc("search", args, RDB::MONOULOG)
1407:       return 0 if !rv
1408:       _popmeta(rv)
1409:       return rv.size > 0 ? rv[0].to_i : 0
1410:     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
1375:     def searchget(names = nil)
1376:       raise ArgumentError if names && !names.is_a?(Array)
1377:       args = @args.dup
1378:       if names
1379:         args.push("get\00"" + names.join("\00""))
1380:       else
1381:         args.push("get")
1382:       end
1383:       @hint = ""
1384:       rv = @rdb.misc("search", args, RDB::MONOULOG)
1385:       return Array::new if !rv
1386:       _popmeta(rv)
1387:       for i in 0...rv.size
1388:         cols = Hash::new
1389:         cary = rv[i].split("\00"")
1390:         cnum = cary.size - 1
1391:         j = 0
1392:         while j < cnum
1393:           cols[cary[j]] = cary[j+1]
1394:           j += 2
1395:         end
1396:         rv[i] = cols
1397:       end
1398:       return rv
1399:     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
1362:     def searchout()
1363:       args = @args.dup
1364:       args.push("out")
1365:       @hint = ""
1366:       rv = @rdb.misc("search", args, 0)
1367:       return false if !rv
1368:       _popmeta(rv)
1369:       return true
1370:     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
1347:     def setlimit(max = 1, skip = 1)
1348:       @args.push("setlimit" + "\00"" + max.to_s + "\00"" + skip.to_s)
1349:       return nil
1350:     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
1339:     def setorder(name, type = QOSTRASC)
1340:       @args.push("setorder" + "\00"" + name + "\00"" + type.to_s)
1341:       return nil
1342:     end

Protected Instance Methods

_args() click to toggle source

Get the internal arguments.

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

Private Instance Methods

_popmeta(res) click to toggle source

Pop meta data from the result list.

      # File tokyotyrant.rb, line 1448
1448:     def _popmeta(res)
1449:       i = res.length - 1
1450:       while i >= 0
1451:         pkey = res[i]
1452:         if pkey =~ /^\00\\00\\[\[HINT\]\]\n/
1453:           @hint = pkey.gsub(/^\00\\00\\[\[HINT\]\]\n/, "")
1454:           res.pop
1455:         else
1456:           break
1457:         end
1458:         i -= 1
1459:       end
1460:     end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.