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

Abstraction of database.

### Methods

add_attr_index add_pseudo_index close doc_num edit_doc err_msg error fatal flush get_doc get_doc_attr merge name new open optimize out_doc put_doc scan_doc search search_meta set_cache_size set_informer set_wildmax 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 << 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

new()

Create a database object.

search_meta(dbs, cond)

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_attr_index(name, type)

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_pseudo_index(path)

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()

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

doc_num()

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

edit_doc(doc)

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

err_msg(ecode)

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

error()

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

fatal()

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

flush(max)

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.

get_doc(id, options)

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.

get_doc_attr(id, name)

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(name, options)

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.

name()

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

open(name, omode)

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(options)

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.

out_doc(id, options)

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.

put_doc(doc, options)

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.

scan_doc(doc, cond)

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(cond)

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

set_cache_size(size, anum, tnum, rnum)

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_informer(informer)

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_wildmax(num)

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

size()

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

sync()

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

uri_to_id(uri)

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.

word_num()

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

[Validate]