Soprano::Index::CLuceneIndex Class Reference

The CLuceneIndex provides a wrapper around a CLucene index which stores RDF statements. More...

#include <Soprano/Index/CLuceneIndex>

Inheritance diagram for Soprano::Index::CLuceneIndex:

Inheritance graph
[legend]

List of all members.

Public Member Functions

 CLuceneIndex (lucene::analysis::Analyzer *analyzer=0)
 ~CLuceneIndex ()
bool open (const QString &folder, bool force=false)
void close ()
bool isOpen () const
int resourceCount () const
int startTransaction ()
bool closeTransaction (int id)
Error::ErrorCode addStatement (const Soprano::Statement &)
Error::ErrorCode removeStatement (const Soprano::Statement &)
lucene::document::Document * documentForResource (const Node &resource)
Iterator< QueryHitsearch (const QString &query)
Iterator< QueryHitsearch (lucene::search::Query *query)
void dump (QTextStream &) const
void clear ()

Static Public Member Functions

static Soprano::Node getResource (lucene::document::Document *document)
static QString defaultSearchField ()


Detailed Description

The CLuceneIndex provides a wrapper around a CLucene index which stores RDF statements.

It is used by the IndexFilterModel to actually handle the index. It has been made visible in the public API to provide the possibility for advanced queries and data modifications.

CLuceneIndex is thread-safe.

Data organization

In the Soprano index each resouce gets its own clucene document. Only statements with literal objects are indexed. The clucene is identified through the statements' subject and then a new field is created that uses the statement's predicate as field name and the statement's object as value. The index ignores all context information.

Warning:
The API is subject to change. Most likely CLucene classes will be wrapped and hidden from the public API.
Author:
Sebastian Trueg <trueg@kde.org>

Definition at line 74 of file cluceneindex.h.


Constructor & Destructor Documentation

Soprano::Index::CLuceneIndex::CLuceneIndex ( lucene::analysis::Analyzer *  analyzer = 0  ) 

Parameters:
analyzer The analyzer to be used. If 0 a standard analyzer will be created.

Soprano::Index::CLuceneIndex::~CLuceneIndex (  ) 

Destructor.

Calls close().


Member Function Documentation

bool Soprano::Index::CLuceneIndex::open ( const QString folder,
bool  force = false 
)

Open the index.

Parameters:
folder The folder where the index is stored.
force If true any CLucene locks on the folder are removed. This is useful if a previous session crashed and left an unused lock lying around.

void Soprano::Index::CLuceneIndex::close (  ) 

Close the index. Write back any changes, close any open transactions. (Is called in ~CLuceneIndex())

bool Soprano::Index::CLuceneIndex::isOpen (  )  const

Returns:
true If the index has been opened successfully.
See also:
open()

int Soprano::Index::CLuceneIndex::resourceCount (  )  const

Get the number of indexed resources.

Returns:
The number of indexed resoruces or -1 on error (In the case of error lastError() provides more information.

int Soprano::Index::CLuceneIndex::startTransaction (  ) 

Start a new transaction. After calling this method multiple fields and statements may be added to the index and nothing is written back to disk. A transaction has to be closed. Otherwise the data will not be written to the index. (All transactions are closed on deletion.)

Methods such as addStatement will start and close a transaction internally if none has been started before.

Returns:
A transaction id that has to be used to close the transaction. This is a safety mechanism to ensure that no other user closes one's transaction. If another transaction has already been started 0 is returned.

bool Soprano::Index::CLuceneIndex::closeTransaction ( int  id  ) 

Close a transaction and write the changes back to the index.

Parameters:
id The transaction ID as returned by startTransaction()
Returns:
true if the transaction was closed, false if no transaction was started, a wrong transaction id has been supplied, or a clucene error occured.

Error::ErrorCode Soprano::Index::CLuceneIndex::addStatement ( const Soprano::Statement  ) 

Indexes a statement.

Returns:
An error code or 0 on success

Error::ErrorCode Soprano::Index::CLuceneIndex::removeStatement ( const Soprano::Statement  ) 

Removes a statement from the index.

Returns:
An error code or 0 on success

lucene::document::Document* Soprano::Index::CLuceneIndex::documentForResource ( const Node resource  ) 

Get a document for a specific resource. This is only possible after starting a transaction.

Parameters:
resource The resource for which a document is requested.
Returns:
The document representing the resource or 0 if no transaction has been started or a clucene error occured.
Warning:
This is an advanced method. Calling this method is thread-safe but using the returned document is not.

Iterator<QueryHit> Soprano::Index::CLuceneIndex::search ( const QString query  ) 

Evaluates the given query. Each hit is a resource and a score. Resource properties may be read from the model.

Parameters:
query The query in the CLucene query language.
Returns:
The results as an iterator over QueryHit objects or an invalid iterator on error.

Iterator<QueryHit> Soprano::Index::CLuceneIndex::search ( lucene::search::Query *  query  ) 

Evaluates the given query. Each hit is a resource and a score. Resource properties may be read from the model.

Parameters:
query The query to evaluate. The iterator takes ownership of the query. Do not delete.it! (If anyone using this understands the weird CLucene memory management enough to fix this issue, please...)
Returns:
The results as an iterator over QueryHit objects or an invalid iterator on error.
Warning:
The result iterator uses the query object.

static Soprano::Node Soprano::Index::CLuceneIndex::getResource ( lucene::document::Document *  document  )  [static]

Returns the Resource corresponding with the specified Document.

static QString Soprano::Index::CLuceneIndex::defaultSearchField (  )  [static]

This is a temporary method which supports the advanced query interface based on CLucene classes.

The Soprano index creates one special field for each indexed resource which contains all data to allow simple queries without property names or URIs.

Returns:
The name of the default CLucene search field to be queried when no properties are known.

void Soprano::Index::CLuceneIndex::dump ( QTextStream  )  const

Dump the index contents to the stream

void Soprano::Index::CLuceneIndex::clear (  ) 

Clear the index, i.e. delete all entries.

Since:
2.1


The documentation for this class was generated from the following file:

Generated on Tue Jul 22 17:39:36 2008 for Soprano by  doxygen 1.5.6