tokyocabinet
Class TDBQRY

java.lang.Object
  extended by tokyocabinet.TDBQRY

public class TDBQRY
extends java.lang.Object

Query is a mechanism to search for and retrieve records corresponding conditions from table database.


Field Summary
static int KWMUBRCT
          KWIC option: mark up by square brackets
static int KWMUCTRL
          KWIC option: mark up by control characters
static int KWMUTAB
          KWIC option: mark up by tabs
static int KWNOOVER
          KWIC option: do not overlap
static int KWPULEAD
          KWIC option: pick up the lead string
static int MSDIFF
          set operation type: difference
static int MSISECT
          set operation type: intersection
static int MSUNION
          set operation type: union
static int QCFTSAND
          query condition: full-text search with all tokens in
static int QCFTSEX
          query condition: full-text search with the compound expression of
static int QCFTSOR
          query condition: full-text search with at least one token in
static int QCFTSPH
          query condition: full-text search with the phrase of
static int QCNEGATE
          query condition: negation flag
static int QCNOIDX
          query condition: no index flag
static int QCNUMBT
          query condition: number is between two tokens of
static int QCNUMEQ
          query condition: number is equal to
static int QCNUMGE
          query condition: number is greater than or equal to
static int QCNUMGT
          query condition: number is greater than
static int QCNUMLE
          query condition: number is less than or equal to
static int QCNUMLT
          query condition: number is less than
static int QCNUMOREQ
          query condition: number is equal to at least one token in
static int QCSTRAND
          query condition: string includes all tokens in
static int QCSTRBW
          query condition: string begins with
static int QCSTREQ
          query condition: string is equal to
static int QCSTREW
          query condition: string ends with
static int QCSTRINC
          query condition: string is included in
static int QCSTROR
          query condition: string includes at least one token in
static int QCSTROREQ
          query condition: string is equal to at least one token in
static int QCSTRRX
          query condition: string matches regular expressions of
static int QONUMASC
          order type: number ascending
static int QONUMDESC
          order type: number descending
static int QOSTRASC
          order type: string ascending
static int QOSTRDESC
          order type: string descending
 
Constructor Summary
TDBQRY(TDB tdb)
          Create a query object.
 
Method Summary
 void addcond(java.lang.String name, int op, java.lang.String expr)
          Add a narrowing condition.
protected  void finalize()
          Release resources.
 java.lang.String hint()
          Get the hint string.
 java.lang.String[] kwic(java.util.Map cols, java.lang.String name, int width, int opts)
          Generate keyword-in-context strings.
 java.util.List metasearch(TDBQRY[] others, int type)
          Retrieve records with multiple query objects and get the set of the result.
 boolean proc(TDBQRYPROC qp)
          Process each corresponding record.
 java.util.List search()
          Execute the search.
 boolean searchout()
          Remove each corresponding record.
 void setlimit(int max, int skip)
          Set the maximum number of records of the result.
 void setorder(java.lang.String name, int type)
          Set the order of the result.
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

KWMUBRCT

public static final int KWMUBRCT
KWIC option: mark up by square brackets

See Also:
Constant Field Values

KWMUCTRL

public static final int KWMUCTRL
KWIC option: mark up by control characters

See Also:
Constant Field Values

KWMUTAB

public static final int KWMUTAB
KWIC option: mark up by tabs

See Also:
Constant Field Values

KWNOOVER

public static final int KWNOOVER
KWIC option: do not overlap

See Also:
Constant Field Values

KWPULEAD

public static final int KWPULEAD
KWIC option: pick up the lead string

See Also:
Constant Field Values

MSDIFF

public static final int MSDIFF
set operation type: difference

See Also:
Constant Field Values

MSISECT

public static final int MSISECT
set operation type: intersection

See Also:
Constant Field Values

MSUNION

public static final int MSUNION
set operation type: union

See Also:
Constant Field Values

QCFTSAND

public static final int QCFTSAND
query condition: full-text search with all tokens in

See Also:
Constant Field Values

QCFTSEX

public static final int QCFTSEX
query condition: full-text search with the compound expression of

See Also:
Constant Field Values

QCFTSOR

public static final int QCFTSOR
query condition: full-text search with at least one token in

See Also:
Constant Field Values

QCFTSPH

public static final int QCFTSPH
query condition: full-text search with the phrase of

See Also:
Constant Field Values

QCNEGATE

public static final int QCNEGATE
query condition: negation flag

See Also:
Constant Field Values

QCNOIDX

public static final int QCNOIDX
query condition: no index flag

See Also:
Constant Field Values

QCNUMBT

public static final int QCNUMBT
query condition: number is between two tokens of

See Also:
Constant Field Values

QCNUMEQ

public static final int QCNUMEQ
query condition: number is equal to

See Also:
Constant Field Values

QCNUMGE

public static final int QCNUMGE
query condition: number is greater than or equal to

See Also:
Constant Field Values

QCNUMGT

public static final int QCNUMGT
query condition: number is greater than

See Also:
Constant Field Values

QCNUMLE

public static final int QCNUMLE
query condition: number is less than or equal to

See Also:
Constant Field Values

QCNUMLT

public static final int QCNUMLT
query condition: number is less than

See Also:
Constant Field Values

QCNUMOREQ

public static final int QCNUMOREQ
query condition: number is equal to at least one token in

See Also:
Constant Field Values

QCSTRAND

public static final int QCSTRAND
query condition: string includes all tokens in

See Also:
Constant Field Values

QCSTRBW

public static final int QCSTRBW
query condition: string begins with

See Also:
Constant Field Values

QCSTREQ

public static final int QCSTREQ
query condition: string is equal to

See Also:
Constant Field Values

QCSTREW

public static final int QCSTREW
query condition: string ends with

See Also:
Constant Field Values

QCSTRINC

public static final int QCSTRINC
query condition: string is included in

See Also:
Constant Field Values

QCSTROR

public static final int QCSTROR
query condition: string includes at least one token in

See Also:
Constant Field Values

QCSTROREQ

public static final int QCSTROREQ
query condition: string is equal to at least one token in

See Also:
Constant Field Values

QCSTRRX

public static final int QCSTRRX
query condition: string matches regular expressions of

See Also:
Constant Field Values

QONUMASC

public static final int QONUMASC
order type: number ascending

See Also:
Constant Field Values

QONUMDESC

public static final int QONUMDESC
order type: number descending

See Also:
Constant Field Values

QOSTRASC

public static final int QOSTRASC
order type: string ascending

See Also:
Constant Field Values

QOSTRDESC

public static final int QOSTRDESC
order type: string descending

See Also:
Constant Field Values
Constructor Detail

TDBQRY

public TDBQRY(TDB tdb)
Create a query object.

Parameters:
tdb - the table database object.
Method Detail

addcond

public void addcond(java.lang.String name,
                    int op,
                    java.lang.String expr)
Add a narrowing condition.

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

finalize

protected void finalize()
Release resources.

Overrides:
finalize in class java.lang.Object

hint

public java.lang.String hint()
Get the hint string.

Returns:
the hint string.

kwic

public java.lang.String[] kwic(java.util.Map cols,
                               java.lang.String name,
                               int width,
                               int opts)
Generate keyword-in-context strings.

Parameters:
cols - a hash containing columns.
name - the name of a column. If it is not defined, the first column of the query is specified.
width - the width of strings picked up around each keyword. If it is negative, the whole text is picked up.
opts - options by bitwise-or: `TDBQRY.KWMUTAB' specifies that each keyword is marked up between two tab characters, `TDBQRY.KWMUCTRL' specifies that each keyword is marked up by the STX (0x02) code and the ETX (0x03) code, `TDBQRY.KWMUBRCT' specifies that each keyword is marked up by the two square brackets, `TDBQRY.KWNOOVER' specifies that each context does not overlap, `TDBQRY.KWPULEAD' specifies that the lead string is picked up forcibly.
Returns:
an array of strings around keywords.

metasearch

public java.util.List metasearch(TDBQRY[] others,
                                 int type)
Retrieve records with multiple query objects and get the set of the result.

Parameters:
others - an array of the query objects except for the self object.
type - a set operation type: `TDBQRY.MSUNION' for the union set, `TDBQRY.MSISECT' for the intersection set, `TDBQRY.MSDIFF' for the difference set. If it is not defined, `TDBQRY.MSUNION' is specified.
Returns:
a list object of the primary keys of the corresponding records. This method does never fail. It returns an empty array even if no record corresponds.
Note:
If the first query object has the order setting, the result array is sorted by the order.

proc

public boolean proc(TDBQRYPROC qp)
Process each corresponding record.

Parameters:
qp - specifies the query processor object.
Returns:
If successful, the return value is true, else, it is false.

search

public java.util.List search()
Execute the search.

Returns:
a list object of the primary keys of the corresponding records. This method does never fail. It returns an empty array even if no record corresponds.

searchout

public boolean searchout()
Remove each corresponding record.

Returns:
If successful, the return value is true, else, it is false.

setlimit

public void setlimit(int max,
                     int skip)
Set the maximum number of records of the result.

Parameters:
max - the maximum number of records of the result. If it is negative, no limit is specified.
skip - the maximum number of records of the result. If it is not more than 0, no record is skipped.

setorder

public void setorder(java.lang.String name,
                     int type)
Set the order of the result.

Parameters:
name - the name of a column. An empty string means the primary key.
type - the order type: `TDBQRY.QOSTRASC' for string ascending, `TDBQRY.QOSTRDESC' for string descending, `TDBQRY.QONUMASC' for number ascending, `TDBQRY.QONUMDESC' for number descending.