estraier
Class Database

java.lang.Object
  extended byestraier.Database

public class Database
extends java.lang.Object

Abstraction of database


Field Summary
static int DBCREAT
          open mode: a writer creating
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 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 GDNOTEXT
          get_doc option: no text
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 java.lang.String VERSION
          version of Hyper Estraier
 
Constructor Summary
Database()
          Create a database object.
 
Method Summary
 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.
 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.
 Result search(Condition cond)
          Search documents corresponding a condition.
 void set_cache_size(double size, int anum, int tnum, int rnum)
          Set the maximum size of the cache memory.
 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

DBCREAT

public static final int DBCREAT
open mode: a writer creating

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

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

GDNOTEXT

public static final int GDNOTEXT
get_doc option: no text

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

VERSION

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

Constructor Detail

Database

public Database()
Create a database object.

Method Detail

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.


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. The two can be specified at the same time by bitwise or.
Returns:
a document object. On error, `null' is returned.

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

public Result search(Condition cond)
Search 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.

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.