estraier
Class Database

java.lang.Object
  extended by estraier.Database

public class Database
extends java.lang.Object

Abstraction of database


Field Summary
static int DBCHRCAT
          open mode: use character category analyzer
static int DBCREAT
          open mode: a writer creating
static int DBHUGE
          open mode: huge tuning
static int DBHUGE2
          open mode: huge tuning second
static int DBHUGE3
          open mode: huge tuning third
static int DBLARGE
          open mode: large tuning
static int DBLCKNB
          open mode: lock without blocking
static int DBNOLCK
          open mode: open without locking
static int DBPERFNG
          open mode: use perfect N-gram analyzer
static int DBREADER
          open mode: open as a reader
static int DBSCASIS
          open mode: refrain from adjustment of scores
static int DBSCINT
          open mode: store scores as integer
static int DBSCVOID
          open mode: store scores as void
static int DBSMALL
          open mode: small tuning
static int DBTRUNC
          open mode: a writer truncating
static int DBWRITER
          open mode: open as a writer
static int ERRACCES
          error code: access forbidden
static int ERRDB
          error code: database problem
static int ERRINVAL
          error code: invalid argument
static int ERRIO
          error code: I/O problem
static int ERRLOCK
          error code: lock failure
static int ERRMISC
          error code: miscellaneous
static int ERRNOERR
          error code: no error
static int ERRNOITEM
          error code: no item
static int GDNOATTR
          get_doc option: no attributes
static int GDNOKWD
          get_doc option: no keywords
static int GDNOTEXT
          get_doc option: no text
static int IDXATTRNUM
          attribute index type: for narrowing with attributes as numbers
static int IDXATTRSEQ
          attribute index type: for multipurpose sequencial access method
static int IDXATTRSTR
          attribute index type: for narrowing with attributes as strings
static int MGCLEAN
          merge option: clean up dispensable regions
static int ODCLEAN
          out_doc option: clean up dispensable regions
static int OPTNODBOPT
          optimize option: omit optimization of the database files
static int OPTNOPURGE
          optimize option: omit purging dispensable region of deleted
static int PDCLEAN
          put_doc option: clean up dispensable regions
static int PDWEIGHT
          put_doc option: weight scores statically when indexing
static java.lang.String VERSION
          version of Hyper Estraier
 
Constructor Summary
Database()
          Create a database object.
 
Method Summary
 boolean add_attr_index(java.lang.String name, int type)
          Add an index for narrowing or sorting with document attributes.
 boolean add_pseudo_index(java.lang.String path)
          Add a pseudo index directory.
 boolean close()
          Close the database.
 int doc_num()
          Get the number of documents.
 boolean edit_doc(Document doc)
          Edit attributes of a document.
 java.lang.String err_msg(int ecode)
          Get the string of an error code.
 int error()
          Get the last happened error code.
 boolean fatal()
          Check whether the database has a fatal error.
protected  void finalize()
          Release resources.
 boolean flush(int max)
          Flush index words in the cache.
 java.lang.String get_doc_attr(int id, java.lang.String name)
          Retrieve the value of an attribute of a document.
 Document get_doc(int id, int options)
          Retrieve a document.
 boolean merge(java.lang.String name, int options)
          Merge another database.
 java.lang.String name()
          Get the name.
 boolean open(java.lang.String name, int omode)
          Open the database.
 boolean optimize(int options)
          Optimize the database.
 boolean out_doc(int id, int options)
          Remove a document.
 boolean put_doc(Document doc, int options)
          Add a document.
 boolean scan_doc(Document doc, Condition cond)
          Check whether a document object matches the phrase of a search condition object definitely.
static Result search_meta(Database[] dbs, Condition cond)
          Search plural databases for documents corresponding a condition.
 Result search(Condition cond)
          Search for documents corresponding a condition.
 void set_cache_size(double size, int anum, int tnum, int rnum)
          Set the maximum size of the cache memory.
 void set_informer(DatabaseInformer informer)
          Set the callback function to inform of database events.
 void set_wildmax(int num)
          Set the maximum number of expansion of wild cards.
 double size()
          Get the size.
 boolean sync()
          Synchronize updating contents.
 int uri_to_id(java.lang.String uri)
          Get the ID of a document specified by URI.
 int word_num()
          Get the number of unique words.
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DBCHRCAT

public static final int DBCHRCAT
open mode: use character category analyzer

See Also:
Constant Field Values

DBCREAT

public static final int DBCREAT
open mode: a writer creating

See Also:
Constant Field Values

DBHUGE

public static final int DBHUGE
open mode: huge tuning

See Also:
Constant Field Values

DBHUGE2

public static final int DBHUGE2
open mode: huge tuning second

See Also:
Constant Field Values

DBHUGE3

public static final int DBHUGE3
open mode: huge tuning third

See Also:
Constant Field Values

DBLARGE

public static final int DBLARGE
open mode: large tuning

See Also:
Constant Field Values

DBLCKNB

public static final int DBLCKNB
open mode: lock without blocking

See Also:
Constant Field Values

DBNOLCK

public static final int DBNOLCK
open mode: open without locking

See Also:
Constant Field Values

DBPERFNG

public static final int DBPERFNG
open mode: use perfect N-gram analyzer

See Also:
Constant Field Values

DBREADER

public static final int DBREADER
open mode: open as a reader

See Also:
Constant Field Values

DBSCASIS

public static final int DBSCASIS
open mode: refrain from adjustment of scores

See Also:
Constant Field Values

DBSCINT

public static final int DBSCINT
open mode: store scores as integer

See Also:
Constant Field Values

DBSCVOID

public static final int DBSCVOID
open mode: store scores as void

See Also:
Constant Field Values

DBSMALL

public static final int DBSMALL
open mode: small tuning

See Also:
Constant Field Values

DBTRUNC

public static final int DBTRUNC
open mode: a writer truncating

See Also:
Constant Field Values

DBWRITER

public static final int DBWRITER
open mode: open as a writer

See Also:
Constant Field Values

ERRACCES

public static final int ERRACCES
error code: access forbidden

See Also:
Constant Field Values

ERRDB

public static final int ERRDB
error code: database problem

See Also:
Constant Field Values

ERRINVAL

public static final int ERRINVAL
error code: invalid argument

See Also:
Constant Field Values

ERRIO

public static final int ERRIO
error code: I/O problem

See Also:
Constant Field Values

ERRLOCK

public static final int ERRLOCK
error code: lock failure

See Also:
Constant Field Values

ERRMISC

public static final int ERRMISC
error code: miscellaneous

See Also:
Constant Field Values

ERRNOERR

public static final int ERRNOERR
error code: no error

See Also:
Constant Field Values

ERRNOITEM

public static final int ERRNOITEM
error code: no item

See Also:
Constant Field Values

GDNOATTR

public static final int GDNOATTR
get_doc option: no attributes

See Also:
Constant Field Values

GDNOKWD

public static final int GDNOKWD
get_doc option: no keywords

See Also:
Constant Field Values

GDNOTEXT

public static final int GDNOTEXT
get_doc option: no text

See Also:
Constant Field Values

IDXATTRNUM

public static final int IDXATTRNUM
attribute index type: for narrowing with attributes as numbers

See Also:
Constant Field Values

IDXATTRSEQ

public static final int IDXATTRSEQ
attribute index type: for multipurpose sequencial access method

See Also:
Constant Field Values

IDXATTRSTR

public static final int IDXATTRSTR
attribute index type: for narrowing with attributes as strings

See Also:
Constant Field Values

MGCLEAN

public static final int MGCLEAN
merge option: clean up dispensable regions

See Also:
Constant Field Values

ODCLEAN

public static final int ODCLEAN
out_doc option: clean up dispensable regions

See Also:
Constant Field Values

OPTNODBOPT

public static final int OPTNODBOPT
optimize option: omit optimization of the database files

See Also:
Constant Field Values

OPTNOPURGE

public static final int OPTNOPURGE
optimize option: omit purging dispensable region of deleted

See Also:
Constant Field Values

PDCLEAN

public static final int PDCLEAN
put_doc option: clean up dispensable regions

See Also:
Constant Field Values

PDWEIGHT

public static final int PDWEIGHT
put_doc option: weight scores statically when indexing

See Also:
Constant Field Values

VERSION

public static final java.lang.String VERSION
version of Hyper Estraier

Constructor Detail

Database

public Database()
Create a database object.

Method Detail

add_attr_index

public boolean add_attr_index(java.lang.String name,
                              int type)
Add an index for narrowing or sorting with document attributes.

Parameters:
name - the name of an attribute.
type - 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.
Returns:
true if success, else it is false.

add_pseudo_index

public boolean add_pseudo_index(java.lang.String path)
Add a pseudo index directory.

Parameters:
path - the path of a pseudo index directory.
Returns:
true if success, else it is false.

close

public boolean close()
Close the database.

Returns:
true if success, else it is false.

doc_num

public int doc_num()
Get the number of documents.

Returns:
the number of documents in the database.

edit_doc

public boolean edit_doc(Document doc)
Edit attributes of a document.

Parameters:
doc - a document object.
Returns:
true if success, else it is false.

err_msg

public java.lang.String err_msg(int ecode)
Get the string of an error code.

Parameters:
ecode - an error code.
Returns:
the string of the error code.

error

public int error()
Get the last happened error code.

Returns:
the last happened error code.

fatal

public boolean fatal()
Check whether the database has a fatal error.

Returns:
true if the database has fatal erroor, else it is false.

finalize

protected void finalize()
Release resources.

Overrides:
finalize in class java.lang.Object

flush

public boolean flush(int max)
Flush index words in the cache.

Parameters:
max - the maximum number of words to be flushed. If it not more than zero, all words are flushed.
Returns:
true if success, else it is false.

get_doc_attr

public java.lang.String get_doc_attr(int id,
                                     java.lang.String name)
Retrieve the value of an attribute of a document.

Parameters:
id - the ID number of a registered document.
name - the name of an attribute.
Returns:
the value of the attribute or `null' if it does not exist.

get_doc

public Document get_doc(int id,
                        int options)
Retrieve a document.

Parameters:
id - the ID number of a registered document.
options - 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.
Returns:
a document object. On error, `null' is returned.

merge

public boolean merge(java.lang.String name,
                     int options)
Merge another database.

Parameters:
name - the name of another database directory.
options - options: `Database.MGCLEAN' to clean up dispensable regions of the deleted document.
Returns:
true if success, else it is false.

name

public java.lang.String name()
Get the name.

Returns:
the name of the database.

open

public boolean open(java.lang.String name,
                    int omode)
Open the database.

Parameters:
name - the name of a database directory.
omode - 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.
Returns:
true if success, else it is false.

optimize

public boolean optimize(int options)
Optimize the database.

Parameters:
options - 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.
Returns:
true if success, else it is false.

out_doc

public boolean out_doc(int id,
                       int options)
Remove a document.

Parameters:
id - the ID number of a registered document.
options - options: `Database.ODCLEAN' to clean up dispensable regions of the deleted document.
Returns:
true if success, else it is false.

put_doc

public boolean put_doc(Document doc,
                       int options)
Add a document.

Parameters:
doc - a document object. The document object should have the URI attribute.
options - options: `Database.PDCLEAN' to clean up dispensable regions of the overwritten document.
Returns:
true if success, else it is false.

scan_doc

public boolean scan_doc(Document doc,
                        Condition cond)
Check whether a document object matches the phrase of a search condition object definitely.

Parameters:
doc - a document object.
cond - a search condition object.
Returns:
true if the document matches the phrase of the condition object definitely, else it is false.

search_meta

public static Result search_meta(Database[] dbs,
                                 Condition cond)
Search plural databases for documents corresponding a condition.

Parameters:
dbs - an array whose elements are database objects.
cond - a condition object.
Returns:
a result object. On error, `null' is returned.

search

public Result search(Condition cond)
Search for documents corresponding a condition.

Parameters:
cond - a condition object.
Returns:
a result object. On error, `null' is returned.

set_cache_size

public void set_cache_size(double size,
                           int anum,
                           int tnum,
                           int rnum)
Set the maximum size of the cache memory.

Parameters:
size - 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 - 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 - 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 - 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.

set_informer

public void set_informer(DatabaseInformer informer)
Set the callback function to inform of database events.

Parameters:
informer - an arbitrary object with a method named as `inform'.

set_wildmax

public void set_wildmax(int num)
Set the maximum number of expansion of wild cards.

Parameters:
num - the maximum number of expansion of wild cards.

size

public double size()
Get the size.

Returns:
the size of the database.

sync

public boolean sync()
Synchronize updating contents.

Returns:
true if success, else it is false.

uri_to_id

public int uri_to_id(java.lang.String uri)
Get the ID of a document specified by URI.

Parameters:
uri - the URI of a registered document.
Returns:
the ID of the document. On error, -1 is returned.

word_num

public int word_num()
Get the number of unique words.

Returns:
the number of unique words in the database.