Soprano  2.7.56
Static Public Member Functions
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:

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
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< QueryHitsearch (const QString &query)
Iterator< QueryHitsearch (lucene::search::Query *query)
void dump (QTextStream &) const
void clear ()
void optimize ()

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

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

Definition at line 75 of file cluceneindex.h.


Constructor & Destructor Documentation

Soprano::Index::CLuceneIndex::CLuceneIndex ( lucene::analysis::Analyzer *  analyzer = 0)
Parameters:
analyzerThe analyzer to be used. If 0 a standard analyzer will be created.

Destructor.

Calls close().


Member Function Documentation

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

Open the index.

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

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

Returns:
true If the index has been opened successfully.
See also:
open()
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.

See also:
search(const QString&)
Since:
2.3
lucene::analysis::Analyzer* Soprano::Index::CLuceneIndex::queryAnalyzer ( ) const

Get the query analyzer set in setQueryAnalyzer. This method is only provided for convenience.

Returns:
The analyzer set in setQueryAnalyzer or 0 if none was set.
Since:
2.3

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.

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.

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

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

Indexes a statement.

Returns:
An error code or 0 on success

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

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

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

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.

Dump the index contents to the stream

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

Since:
2.1

Optimize the index for search. This makes sense after adding or removing a large number of statements.

Since:
2.2

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