Soprano
2.9.2
|
The CLuceneIndex provides a wrapper around a CLucene index which stores RDF statements. More...
#include <Soprano/Index/CLuceneIndex>
Public Member Functions | |
CLuceneIndex (lucene::analysis::Analyzer *analyzer=0) | |
~CLuceneIndex () | |
bool | open (const QString &folder, bool force=false) |
void | close () |
bool | isOpen () const |
void | setQueryAnalyzer (lucene::analysis::Analyzer *analyzer) |
lucene::analysis::Analyzer * | queryAnalyzer () 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< QueryHit > | search (const QString &query) |
Iterator< QueryHit > | search (lucene::search::Query *query) |
void | dump (QTextStream &) const |
void | clear () |
void | optimize () |
![]() | |
virtual | ~ErrorCache () |
virtual Error | lastError () const |
Static Public Member Functions | |
static Soprano::Node | getResource (lucene::document::Document *document) |
static QString | defaultSearchField () |
Additional Inherited Members | |
![]() | |
ErrorCache () | |
void | clearError () const |
void | setError (const Error &) const |
void | setError (const QString &errorMessage, int code=ErrorUnknown) const |
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 resource 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.
Definition at line 75 of file cluceneindex.h.
Soprano::Index::CLuceneIndex::CLuceneIndex | ( | lucene::analysis::Analyzer * | analyzer = 0 ) |
analyzer | The analyzer to be used. If 0 a standard analyzer will be created. |
Soprano::Index::CLuceneIndex::~CLuceneIndex | ( | ) |
Destructor.
Calls close().
bool Soprano::Index::CLuceneIndex::open | ( | const QString & | folder, |
bool | force = false |
||
) |
Open the index.
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 |
true
If the index has been opened successfully. void Soprano::Index::CLuceneIndex::setQueryAnalyzer | ( | lucene::analysis::Analyzer * | analyzer) |
Optionally set the analyzer to be used for query parsing. By default the index analyzer specified in the constructor is used.
CLuceneIndex will not take ownership of the analyzer.
lucene::analysis::Analyzer* Soprano::Index::CLuceneIndex::queryAnalyzer | ( | ) | const |
Get the query analyzer set in setQueryAnalyzer. This method is only provided for convenience.
int Soprano::Index::CLuceneIndex::resourceCount | ( | ) | const |
Get the number of indexed resources.
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.
bool Soprano::Index::CLuceneIndex::closeTransaction | ( | int | id) |
Close a transaction and write the changes back to the index.
id | The transaction ID as returned by startTransaction() |
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.
Error::ErrorCode Soprano::Index::CLuceneIndex::removeStatement | ( | const Soprano::Statement & | ) |
Removes a statement from the index.
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.
resource | The resource for which a document is requested. |
Evaluates the given query. Each hit is a resource and a score. Resource properties may be read from the model.
query | The query in the CLucene query language. |
Evaluates the given query. Each hit is a resource and a score. Resource properties may be read from the model.
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...) |
|
static |
Returns the Resource corresponding with the specified Document.
|
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.
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.
void Soprano::Index::CLuceneIndex::optimize | ( | ) |
Optimize the index for search. This makes sense after adding or removing a large number of statements.