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

Abstraction of database.

Methods

close   doc_num   edit_doc   err_msg   error   fatal   flush   get_doc   get_doc_attr   name   new   open   optimize   out_doc   put_doc   scan_doc   search   set_cache_size   size   sync   uri_to_id   word_num  

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 << 6   open mode: use perfect N-gram analyzer
OPTNOPURGE = 1 << 0   optimize option: omit purging dispensable region of deleted
OPTNODBOPT = 1 << 1   optimize option: omit optimization of the database files
PDCLEAN = 1 << 0   put_doc option: clean up dispensable regions
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

Public Class methods

Create a database object.

Public Instance methods

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. The two 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.

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

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]