Class Estraier::Database
In: estraier-doc.rb
Parent: Object

++ Abstraction of database.


Methods

Constants

VERSION = "0.0.0"   version of Hyper Estraier
ERRNOERR = 0   error code: no error
ERRINVAL = 1   error code: invalid argument
ERRACCES = 2   error code: access forbidden
ERRLOCK = 3   error code: lock failure
ERRDB = 4   error code: database problem
ERRIO = 5   error code: I/O problem
ERRNOITEM = 6   error code: no item
ERRMISC = 9999   error code: miscellaneous
DBREADER = 1 << 0   open mode: open as a reader
DBWRITER = 1 << 1   open mode: open as a writer
DBCREAT = 1 << 2   open mode: a writer creating
DBTRUNC = 1 << 3   open mode: a writer truncating
DBNOLCK = 1 << 4   open mode: open without locking
DBLCKNB = 1 << 5   open mode: lock without blocking
DBPERFNG = 1 << 10   open mode: use perfect N-gram analyzer
DBCHRCAT = 1 << 11   open mode: use character category analyzer
DBSMALL = 1 << 20   open mode: small tuning
DBLARGE = 1 << 21   open mode: large tuning
DBHUGE = 1 << 22   open mode: huge tuning
DBHUGE2 = 1 << 23   open mode: huge tuning second
DBHUGE3 = 1 << 24   open mode: huge tuning third
DBSCVOID = 1 << 25   open mode: store scores as void
DBSCINT = 1 << 26   open mode: store scores as integer
DBSCASIS = 1 << 27   open mode: refrain from adjustment of scores
IDXATTRSEQ = 0   attribute index type: for multipurpose sequencial access method
IDXATTRSTR = 1   attribute index type: for narrowing with attributes as strings
IDXATTRNUM = 2   attribute index type: for narrowing with attributes as numbers
OPTNOPURGE = 1 << 0   optimize option: omit purging dispensable region of deleted
OPTNODBOPT = 1 << 1   optimize option: omit optimization of the database files
MGCLEAN = 1 << 0   merge option: clean up dispensable regions
PDCLEAN = 1 << 0   put_doc option: clean up dispensable regions
PDWEIGHT = 1 << 1   put_doc option: weight scores statically when indexing
ODCLEAN = 1 << 0   out_doc option: clean up dispensable regions
GDNOATTR = 1 << 0   get_doc option: no attributes
GDNOTEXT = 1 << 1   get_doc option: no text
GDNOKWD = 1 << 2   get_doc option: no keywords

Public Class methods

Create a database object.

Search plural databases for documents corresponding a condition. `dbs’ specifies an array whose elements are database objects. `cond’ specifies a condition object. The return value is a result object. On error, `nil’ is returned.

Public Instance methods

Add an index for narrowing or sorting with document attributes. `name’ specifies the name of an attribute. `type’ specifies the data type of attribute index; `Database::IDXATTRSEQ’ for multipurpose sequencial access method, `Database::IDXATTRSTR’ for narrowing with attributes as strings, `Database::IDXATTRNUM’ for narrowing with attributes as numbers. The return value is true if success, else it is false.

Add a pseudo index directory. `path’ specifies the path of a pseudo index directory. The return value is true if success, else it is false.

Close the database. The return value is true if success, else it is false.

Get the number of documents. The return value is the number of documents in the database.

Edit attributes of a document. `doc’ specifies a document object. The return value is true if success, else it is false.

Get the string of an error code. `ecode’ specifies an error code. The return value is the string of the error code.

Get the last happened error code. The return value is the last happened error code.

Check whether the database has a fatal error. The return value is true if the database has fatal erroor, else it is false.

Flush index words in the cache. `max’ specifies the maximum number of words to be flushed. If it not more than zero, all words are flushed. The return value is true if success, else it is false.

Retrieve a document. `id’ specifies the ID number of a registered document. `options’ specifies options: `Database::GDNOATTR’ to ignore attributes, `Database::GDNOTEXT’ to ignore the body text, `Database::GDNOKWD’ to ignore keywords. The three can be specified at the same time by bitwise or. The return value is a document object. On error, `nil’ is returned.

Retrieve the value of an attribute of a document. `id’ specifies the ID number of a registered document. `name’ specifies the name of an attribute. The return value is the value of the attribute or `nil’ if it does not exist.

Merge another database. `name’ specifies the name of another database directory. `options’ specifies options: `Database::MGCLEAN’ to clean up dispensable regions of the deleted document. The return value is true if success, else it is false.

Get the name. The return value is the name of the database.

Open a database. `name’ specifies the name of a database directory. `omode’ specifies open modes: `Database::DBWRITER’ as a writer, `Database::DBREADER’ as a reader. If the mode is `Database::DBWRITER’, the following may be added by bitwise or: `Database::DBCREAT’, which means it creates a new database if not exist, `Database::DBTRUNC’, which means it creates a new database regardless if one exists. Both of `Database::DBREADER’ and `Database::DBWRITER’ can be added to by bitwise or: `Database::DBNOLCK’, which means it opens a database file without file locking, or `Database::DBLCKNB’, which means locking is performed without blocking. If `Database::DBNOLCK’ is used, the application is responsible for exclusion control. `Database::DBCREAT’ can be added to by bitwise or: `Database::DBPERFNG’, which means N-gram analysis is performed against European text also, `Database::DBCHACAT’, which means character category analysis is performed instead of N-gram analysis, `Database::DBSMALL’, which means the index is tuned to register less than 50000 documents, `Database::DBLARGE’, which means the index is tuned to register more than 300000 documents, `Database::DBHUGE’, which means the index is tuned to register more than 1000000 documents, `Database::DBHUGE2’, which means the index is tuned to register more than 5000000 documents, `Database::DBHUGE3’, which means the index is tuned to register more than 10000000 documents, `Database::DBSCVOID’, which means scores are stored as void, `Database::DBSCINT’, which means scores are stored as 32-bit integer, `Database::DBSCASIS’, which means scores are stored as-is and marked not to be tuned when search. The return value is true if success, else it is false.

Optimize the database. `options’ specifies options: `Database::OPTNOPURGE’ to omit purging dispensable region of deleted documents, `Database::OPTNODBOPT’ to omit optimization of the database files. The two can be specified at the same time by bitwise or. The return value is true if success, else it is false.

Remove a document. `id’ specifies the ID number of a registered document. `options’ specifies options: `Database::ODCLEAN’ to clean up dispensable regions of the deleted document. The return value is true if success, else it is false.

Add a document. `doc’ specifies a document object. The document object should have the URI attribute. `options’ specifies options: `Database::PDCLEAN’ to clean up dispensable regions of the overwritten document. The return value is true if success, else it is false.

Check whether a document object matches the phrase of a search condition object definitely. `doc’ specifies a document object. `cond’ specifies a search condition object. The return value is true if the document matches the phrase of the condition object definitely, else it is false.

Search for documents corresponding a condition. `cond’ specifies a condition object. The return value is a result object. On error, `nil’ is returned.

Set the maximum size of the cache memory. `size’ specifies the maximum size of the index cache. By default, it is 64MB. If it is not more than 0, the current size is not changed. `anum’ specifies the maximum number of cached records for document attributes. By default, it is 8192. If it is not more than 0, the current size is not changed. `tnum’ specifies the maximum number of cached records for document texts. By default, it is 1024. If it is not more than 0, the current size is not changed. `rnum’ specifies the maximum number of cached records for occurrence results. By default, it is 256. If it is not more than 0, the current size is not changed. The return value is always `nil’.

Set the callback function to inform of database events. `informer’ specifies an arbitrary object with a method named as `inform’. The method should have one parameter for a string of a message of each event. The return value is always `nil’.

Set the maximum number of expansion of wild cards. `num’ specifies the maximum number of expansion of wild cards. The return value is always `nil’.

Get the size. The return value is the size of the database.

Synchronize updating contents. The return value is true if success, else it is false.

Get the ID of a document specified by URI. `uri’ specifies the URI of a registered document. The return value is the ID of the document. On error, -1 is returned.

Get the number of unique words. The return value is the number of unique words in the database.

[Validate]