Soprano 2.9.4
Public Member Functions | Static Public Member Functions | List of all members
Soprano::Index::IndexFilterModel Class Reference

The IndexFilterModel provides a full text index around any Soprano Model. More...

#include <Soprano/Index/IndexFilterModel>

+ Inheritance diagram for Soprano::Index::IndexFilterModel:

Public Member Functions

 IndexFilterModel (const QString &indexDir, Soprano::Model *model=0)
 
 IndexFilterModel (CLuceneIndex *index, Soprano::Model *model=0)
 
 ~IndexFilterModel ()
 
CLuceneIndexindex () const
 
Soprano::Error::ErrorCode addStatement (const Soprano::Statement &statement)
 
Soprano::Error::ErrorCode removeStatement (const Soprano::Statement &statement)
 
Soprano::Error::ErrorCode removeAllStatements (const Soprano::Statement &statement)
 
QueryResultIterator executeQuery (const QString &query, Query::QueryLanguage language, const QString &userQueryLanguage=QString()) const
 
void setTransactionCacheSize (int size)
 
int transactionCacheSize () const
 
void rebuildIndex ()
 
void optimizeIndex ()
 
void addIndexOnlyPredicate (const QUrl &predicate)
 
void setIndexOnlyPredicates (const QList< QUrl > &predicates)
 
QList< QUrlindexOnlyPredicates () const
 
void addForceIndexPredicate (const QUrl &predicate)
 
void setForceIndexPredicates (const QList< QUrl > &predicates)
 
QList< QUrlforceIndexPredicates () const
 
virtual Error::ErrorCode addStatement (const Statement &statement)
 
Error::ErrorCode addStatement (const Node &subject, const Node &predicate, const Node &object, const Node &context=Node())
 
virtual Error::ErrorCode addStatement (const Statement &statement)=0
 
Error::ErrorCode addStatement (const Node &subject, const Node &predicate, const Node &object, const Node &context=Node())
 
virtual Error::ErrorCode removeStatement (const Statement &statement)
 
Error::ErrorCode removeStatement (const Node &subject, const Node &predicate, const Node &object, const Node &context=Node())
 
virtual Error::ErrorCode removeStatement (const Statement &statement)=0
 
Error::ErrorCode removeStatement (const Node &subject, const Node &predicate, const Node &object, const Node &context=Node())
 
virtual Error::ErrorCode removeAllStatements (const Statement &statement)
 
Error::ErrorCode removeAllStatements (const Node &subject, const Node &predicate, const Node &object, const Node &context=Node())
 
virtual Error::ErrorCode removeAllStatements (const Statement &statement)=0
 
Error::ErrorCode removeAllStatements (const Node &subject, const Node &predicate, const Node &object, const Node &context=Node())
 
Error::ErrorCode removeAllStatements ()
 
- Public Member Functions inherited from Soprano::FilterModel
virtual ~FilterModel ()
 
virtual void setParentModel (Model *model)
 
virtual ModelparentModel () const
 
virtual Error::ErrorCode addStatement (const Statement &statement)
 
Error::ErrorCode addStatement (const Node &subject, const Node &predicate, const Node &object, const Node &context=Node())
 
virtual Error::ErrorCode removeStatement (const Statement &statement)
 
Error::ErrorCode removeStatement (const Node &subject, const Node &predicate, const Node &object, const Node &context=Node())
 
virtual Error::ErrorCode removeAllStatements (const Statement &statement)
 
Error::ErrorCode removeAllStatements (const Node &subject, const Node &predicate, const Node &object, const Node &context=Node())
 
virtual StatementIterator listStatements (const Statement &partial) const
 
StatementIterator listStatements (const Node &subject, const Node &predicate, const Node &object, const Node &context=Node()) const
 
virtual NodeIterator listContexts () const
 
virtual QueryResultIterator executeQuery (const QString &query, Query::QueryLanguage language, const QString &userQueryLanguage=QString()) const
 
virtual bool containsStatement (const Statement &statement) const
 
bool containsStatement (const Node &subject, const Node &predicate, const Node &object, const Node &context=Node()) const
 
virtual bool containsAnyStatement (const Statement &statement) const
 
bool containsAnyStatement (const Node &subject, const Node &predicate, const Node &object, const Node &context=Node()) const
 
virtual bool isEmpty () const
 
virtual int statementCount () const
 
virtual Error::ErrorCode write (QTextStream &os) const
 
virtual Node createBlankNode ()
 
virtual Error::ErrorCode addStatement (const Statement &statement)=0
 
Error::ErrorCode addStatement (const Node &subject, const Node &predicate, const Node &object, const Node &context=Node())
 
virtual Error::ErrorCode removeStatement (const Statement &statement)=0
 
Error::ErrorCode removeStatement (const Node &subject, const Node &predicate, const Node &object, const Node &context=Node())
 
virtual Error::ErrorCode removeAllStatements (const Statement &statement)=0
 
Error::ErrorCode removeAllStatements (const Node &subject, const Node &predicate, const Node &object, const Node &context=Node())
 
Error::ErrorCode removeAllStatements ()
 
virtual StatementIterator listStatements (const Statement &partial) const=0
 
StatementIterator listStatements (const Node &subject, const Node &predicate, const Node &object, const Node &context=Node()) const
 
StatementIterator listStatements () const
 
virtual bool containsStatement (const Statement &statement) const=0
 
bool containsStatement (const Node &subject, const Node &predicate, const Node &object, const Node &context=Node()) const
 
virtual bool containsAnyStatement (const Statement &statement) const=0
 
bool containsAnyStatement (const Node &subject, const Node &predicate, const Node &object, const Node &context=Node()) const
 
- Public Member Functions inherited from Soprano::Model
virtual ~Model ()
 
virtual Error::ErrorCode addStatement (const Statement &statement)=0
 
Error::ErrorCode addStatement (const Node &subject, const Node &predicate, const Node &object, const Node &context=Node())
 
Error::ErrorCode addStatements (const QList< Statement > &statements)
 
virtual Error::ErrorCode removeStatement (const Statement &statement)=0
 
Error::ErrorCode removeStatement (const Node &subject, const Node &predicate, const Node &object, const Node &context=Node())
 
virtual Error::ErrorCode removeAllStatements (const Statement &statement)=0
 
Error::ErrorCode removeAllStatements (const Node &subject, const Node &predicate, const Node &object, const Node &context=Node())
 
Error::ErrorCode removeStatements (const QList< Statement > &statements)
 
Error::ErrorCode removeContext (const Node &)
 
Error::ErrorCode removeAllStatements ()
 
virtual StatementIterator listStatements (const Statement &partial) const =0
 
StatementIterator listStatements (const Node &subject, const Node &predicate, const Node &object, const Node &context=Node()) const
 
StatementIterator listStatements () const
 
StatementIterator listStatementsInContext (const Node &context) const
 
virtual NodeIterator listContexts () const =0
 
virtual QueryResultIterator executeQuery (const QString &query, Query::QueryLanguage language, const QString &userQueryLanguage=QString()) const =0
 
virtual bool containsAnyStatement (const Statement &statement) const =0
 
bool containsAnyStatement (const Node &subject, const Node &predicate, const Node &object, const Node &context=Node()) const
 
virtual bool containsStatement (const Statement &statement) const =0
 
bool containsStatement (const Node &subject, const Node &predicate, const Node &object, const Node &context=Node()) const
 
bool containsContext (const Node &context) const
 
virtual bool isEmpty () const =0
 
virtual int statementCount () const =0
 
virtual Error::ErrorCode write (QTextStream &os) const
 
virtual Node createBlankNode ()=0
 
- Public Member Functions inherited from QObject
 QObject (QObject *parent=0)
 
 blockSignals (bool block)
 
 childEvent (QChildEvent *event)
 
 children ()
 
 connect (const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type=Qt::AutoCompatConnection)
 
 connect (const QObject *sender, const char *signal, const char *method, Qt::ConnectionType type=Qt::AutoCompatConnection)
 
 connectNotify (const char *signal)
 
 customEvent (QEvent *event)
 
 deleteLater ()
 
 destroyed (QObject *obj=0)
 
 disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *method)
 
 disconnect (const char *signal=0, const QObject *receiver=0, const char *method=0)
 
 disconnect (const QObject *receiver, const char *method=0)
 
 disconnectNotify (const char *signal)
 
 dumpObjectInfo ()
 
 dumpObjectTree ()
 
 dynamicPropertyNames ()
 
 event (QEvent *e)
 
 eventFilter (QObject *watched, QEvent *event)
 
 findChild (const QString &name=QString()
 
 findChildren (const QString &name=QString()
 
 findChildren (const QRegExp &regExp)
 
 inherits (const char *className)
 
 installEventFilter (QObject *filterObj)
 
 isWidgetType ()
 
 killTimer (int id)
 
 metaObject ()
 
 moveToThread (QThread *targetThread)
 
 parent ()
 
 property (const char *name)
 
 receivers (const char *signal)
 
 removeEventFilter (QObject *obj)
 
 sender ()
 
 setParent (QObject *parent)
 
 setProperty (const char *name, const QVariant &value)
 
 signalsBlocked ()
 
 startTimer (int interval)
 
 thread ()
 
 timerEvent (QTimerEvent *event)
 
 tr (const char *sourceText, const char *comment=0, int n=-1)
 
 trUtf8 (const char *sourceText, const char *comment=0, int n=-1)
 
 staticMetaObject
 
 QObject (QObject *parent, const char *name)
 
 checkConnectArgs (const char *signal, const QObject *object, const char *method)
 
 child (const char *objName, const char *inheritsClass=0, bool recursiveSearch=true)
 
 className ()
 
 insertChild (QObject *object)
 
 isA (const char *className)
 
 name ()
 
 name (const char *defaultName)
 
 normalizeSignalSlot (const char *signalSlot)
 
 removeChild (QObject *object)
 
 setName (const char *name)
 
- Public Member Functions inherited from Soprano::Error::ErrorCache
virtual ~ErrorCache ()
 
virtual Error lastError () const
 

Static Public Member Functions

static QString encodeStringForLuceneQuery (const QString &value)
 
static QString encodeUriForLuceneQuery (const QUrl &uri)
 

Additional Inherited Members

- Signals inherited from Soprano::Model
void statementsAdded ()
 
void statementsRemoved ()
 
void statementAdded (const Soprano::Statement &statement)
 
void statementRemoved (const Soprano::Statement &statement)
 
- Protected Member Functions inherited from Soprano::FilterModel
 FilterModel ()
 
 FilterModel (Model *parent)
 
virtual void parentStatementsAdded ()
 
virtual void parentStatementsRemoved ()
 
virtual void parentStatementAdded (const Statement &)
 
virtual void parentStatementRemoved (const Statement &)
 
- Protected Member Functions inherited from Soprano::Model
 Model ()
 
- Protected Member Functions inherited from Soprano::Error::ErrorCache
 ErrorCache ()
 
void clearError () const
 
void setError (const Error &) const
 
void setError (const QString &errorMessage, int code=ErrorUnknown) const
 

Detailed Description

The IndexFilterModel provides a full text index around any Soprano Model.

All statements with a literal object will be indexed. The literals can then be searched with CLucene queries. More details regarding queries can be found in the documentation fo executeQuery().

Author
Sebastian Trueg trueg.nosp@m.@kde.nosp@m..org

Definition at line 61 of file indexfiltermodel.h.

Constructor & Destructor Documentation

◆ IndexFilterModel() [1/2]

Soprano::Index::IndexFilterModel::IndexFilterModel ( const QString indexDir,
Soprano::Model model = 0 
)

Create a new index model.

Parameters
indexDirThe directory where the index should be stored. If the directory already contains an index, it will be used. Otherwise a new one will be created.
modelThe parent model to forward the calls to. If 0 the Model has to be set later on with FilterModel::setParentModel.

◆ IndexFilterModel() [2/2]

Soprano::Index::IndexFilterModel::IndexFilterModel ( CLuceneIndex index,
Soprano::Model model = 0 
)

Create a new index model.

Parameters
indexThe index to be used. The filter model will NOT take ownership of the index. The caller has to take care of deleting the index.
modelThe parent model to forward the calls to. If 0 the Model has to be set later on with FilterModel::setParentModel.

◆ ~IndexFilterModel()

Soprano::Index::IndexFilterModel::~IndexFilterModel ( )

Destructor.

Member Function Documentation

◆ index()

CLuceneIndex * Soprano::Index::IndexFilterModel::index ( ) const

Retrieve the index used by this index model.

◆ addStatement() [1/5]

Soprano::Error::ErrorCode Soprano::Index::IndexFilterModel::addStatement ( const Soprano::Statement statement)
virtual

Adds a new statement.

This will index the statement and then forward the call to the parent model. Normally only statements with literal objects are indexed. An exception are those statements with predicates that are set via setForceIndexPredicates.

Reimplemented from Soprano::FilterModel.

◆ removeStatement() [1/5]

Soprano::Error::ErrorCode Soprano::Index::IndexFilterModel::removeStatement ( const Soprano::Statement statement)
virtual

Removes a statement.

This will remove the statement from the index and then forward the call to the parent model.

Reimplemented from Soprano::FilterModel.

◆ removeAllStatements() [1/6]

Soprano::Error::ErrorCode Soprano::Index::IndexFilterModel::removeAllStatements ( const Soprano::Statement statement)
virtual

Removes statements.

This will remove the statements from the index and then forward the call to the parent model.

Reimplemented from Soprano::FilterModel.

◆ executeQuery()

QueryResultIterator Soprano::Index::IndexFilterModel::executeQuery ( const QString query,
Query::QueryLanguage  language,
const QString userQueryLanguage = QString() 
) const
virtual

The IndexFilterModel is currently based on CLucene. While the index itself is available via index() and allows querying via CLucene queries it is not available over the Soprano::Client interface. Thus, CLucene queries are supported through this method and will return QueryHit objects wrapped in a QueryResultIterator.

Future versions of Soprano will support querying the index through the Soprano::Query API (still unfinished and unstable).

Parameters
queryThe query string. This can be a CLucene query in which case the query will be passed to CLuceneIndex.
languageThe query language. Set to Soprano::Query::QueryLanguageUser for CLucene queries.
userQueryLanguageIf language equals Query::QueryLanguageUser userQueryLanguage defines the language to use. Use "lucene" to perform CLucene queries.
Returns
An iterator over all results matching the query, on error an invalid iterator is returned. In case of a CLucene query the iterator will wrap a set of QueryHit objects through the bindings "resource" and "score".
See also
CLuceneIndex::search()

Reimplemented from Soprano::FilterModel.

◆ setTransactionCacheSize()

void Soprano::Index::IndexFilterModel::setTransactionCacheSize ( int  size)

Set the number or addStatement operations that are to be cached in the index. The default value is 1 which means that no caching occurs. Be aware that query operations will always close cached transactions.

Parameters
sizeThe number of operations that should be handled in one transaction. Set to 1 to disable.
See also
CLuceneIndex::startTransaction, CLuceneIndex::closeTransaction

◆ transactionCacheSize()

int Soprano::Index::IndexFilterModel::transactionCacheSize ( ) const

The number of addStatement operations to cache in one transaction.

See also
setTransactionCacheSize

◆ rebuildIndex()

void Soprano::Index::IndexFilterModel::rebuildIndex ( )

Rebuild the complete index. This means that the index will be cleared and all literal statements will be re-indexed.

This method is purely intended for maintenance.

Since
2.1

◆ optimizeIndex()

void Soprano::Index::IndexFilterModel::optimizeIndex ( )

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

See also
CLuceneIndex::optimize
Since
2.2

◆ addIndexOnlyPredicate()

void Soprano::Index::IndexFilterModel::addIndexOnlyPredicate ( const QUrl predicate)

Add a predicate which should only be indexed. This might be useful for very large literals whose value is of no interest but which should be searchable.

Parameters
predicateThe predicate that should only be indexed but not stored in the underlying Model.
See also
indexOnlyPredicates, setIndexOnlyPredicates
Since
2.1

◆ setIndexOnlyPredicates()

void Soprano::Index::IndexFilterModel::setIndexOnlyPredicates ( const QList< QUrl > &  predicates)

Set the predicates that should only be indexed. This might be useful for very large literals whose value is of no interest but which should be searchable.

Parameters
predicatesA list of predicates that should only be indexed but not stored in the underlying Model.
See also
indexOnlyPredicates, addIndexOnlyPredicate
Since
2.1

◆ indexOnlyPredicates()

QList< QUrl > Soprano::Index::IndexFilterModel::indexOnlyPredicates ( ) const

The IndexFilterModel supports to not forward certain predicates to the parent Model but only index their value. This might be useful for very large literals whose value is of no interest but which should be searchable.

Returns
A list of predicates that will only be indexed but not stored in the underlying Model.
See also
addIndexOnlyPredicate, setIndexOnlyPredicates
Since
2.1

◆ addForceIndexPredicate()

void Soprano::Index::IndexFilterModel::addForceIndexPredicate ( const QUrl predicate)

Add a predicate which should be indexed even if the object is a resource. See setForceIndexPredicates for a detailed explanation.

Parameters
predicateThe predicate that should be indexed in any case.
See also
forceIndexPredicates, setForceIndexPredicates
Since
2.2

◆ setForceIndexPredicates()

void Soprano::Index::IndexFilterModel::setForceIndexPredicates ( const QList< QUrl > &  predicates)

Normally only statements with a literal object are indexed when added thorugh addStatement. In some cases however, it is useful to also index resource objects.

Statement with a resource object (a URI) and a predicate that matches one of the force index predicates, are converted to strings using QUrl::toEncoded and added to the index non-tokenized. Thus, the resources will be searchable directly via a 'field:uri' query but not via the default search field.

A typical and very useful predicate is Vocabulary::RDF::type(). This allows to restrict the type of resources in lucene queries:

model->executeQuery( QString( "foobar AND %1:%2" )
.arg( encodeUriForLuceneQuery( RDF::type() ) )
.arg( encodeUriForLuceneQuery( myType ) ),
"lucene" );
static QString encodeUriForLuceneQuery(const QUrl &uri)
Parameters
predicatesThe predicates that should be indexed in any case.
See also
forceIndexPredicates, addForceIndexPredicate
Since
2.2

◆ forceIndexPredicates()

QList< QUrl > Soprano::Index::IndexFilterModel::forceIndexPredicates ( ) const

See setForceIndexPredicates for a detailed explanation.

Returns
A list of predicates that will be indexed even if the object is not a literal.
See also
addForceIndexPredicate, setForceIndexPredicates
Since
2.2

◆ encodeStringForLuceneQuery()

static QString Soprano::Index::IndexFilterModel::encodeStringForLuceneQuery ( const QString value)
static

Encodes a string to be used in a lucene query. String values may contain characters that are reserved in lucene queries. These are property escaped by this method.

This method converts an arbitrary string into a string that can be used in a lucene query.

Parameters
valueThe string to be encoded.
Returns
An encoded and escaped string representation of the provided string.
See also
encodeUriForLuceneQuery
Since
2.2

◆ encodeUriForLuceneQuery()

static QString Soprano::Index::IndexFilterModel::encodeUriForLuceneQuery ( const QUrl uri)
static

Encodes a URI to be used in a lucene query. URIs often contain characters that are reserved in lucene queries and, thus, need to be escaped. In addition, the URIs are encoded by the index model for storage in clucene.

This method converts a URI into a string that can be used in a lucene query.

Parameters
uriThe URI to be encoded.
Returns
An encoded and escaped string representation of the URI.
See also
encodeStringForLuceneQuery
Since
2.2

◆ addStatement() [2/5]

virtual Error::ErrorCode Soprano::FilterModel::addStatement ( const Statement statement)
virtual

Default implementation simply pipes the call through to the parent model.

Reimplemented from Soprano::FilterModel.

◆ addStatement() [3/5]

Error::ErrorCode Soprano::FilterModel::addStatement ( const Node subject,
const Node predicate,
const Node object,
const Node context = Node() 
)

◆ addStatement() [4/5]

virtual Error::ErrorCode Soprano::Model::addStatement ( const Statement statement)
virtual

Add the Statement to the Model.

Parameters
statementThe Statement to add.

Reimplemented from Soprano::FilterModel.

◆ addStatement() [5/5]

Error::ErrorCode Soprano::Model::addStatement ( const Node subject,
const Node predicate,
const Node object,
const Node context = Node() 
)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ removeStatement() [2/5]

virtual Error::ErrorCode Soprano::FilterModel::removeStatement ( const Statement statement)
virtual

Default implementation simply pipes the call through to the parent model.

Reimplemented from Soprano::FilterModel.

◆ removeStatement() [3/5]

Error::ErrorCode Soprano::FilterModel::removeStatement ( const Node subject,
const Node predicate,
const Node object,
const Node context = Node() 
)

◆ removeStatement() [4/5]

virtual Error::ErrorCode Soprano::Model::removeStatement ( const Statement statement)
virtual

Remove one statement. For removing statements with wildward matching see removeAllStatements().

Parameters
statementThe statement that should be removed. This has to be a valid statement.
Returns
Error::ErrorNone on success and an error code if statement was invalid or an error occured.

Reimplemented from Soprano::FilterModel.

◆ removeStatement() [5/5]

Error::ErrorCode Soprano::Model::removeStatement ( const Node subject,
const Node predicate,
const Node object,
const Node context = Node() 
)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ removeAllStatements() [2/6]

virtual Error::ErrorCode Soprano::FilterModel::removeAllStatements ( const Statement statement)
virtual

Default implementation simply pipes the call through to the parent model.

Reimplemented from Soprano::FilterModel.

◆ removeAllStatements() [3/6]

Error::ErrorCode Soprano::FilterModel::removeAllStatements ( const Node subject,
const Node predicate,
const Node object,
const Node context = Node() 
)

◆ removeAllStatements() [4/6]

virtual Error::ErrorCode Soprano::Model::removeAllStatements ( const Statement statement)
virtual

Remove all statements that match the partial statement. For removing one specific statement see removeStatement().

Parameters
statementA possible partially defined statement that serves as a filter for all statements that should be removed.

Reimplemented from Soprano::FilterModel.

◆ removeAllStatements() [5/6]

Error::ErrorCode Soprano::Model::removeAllStatements ( const Node subject,
const Node predicate,
const Node object,
const Node context = Node() 
)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Parameters
subjectThe subject node to match. Can be empty as a wildcard.
predicateThe predicate node to match. Can be empty as a wildcard.
objectThe object node to match. Can be empty as a wildcard.
contextThe context node to match. Can be empty as a wildcard.

◆ removeAllStatements() [6/6]

Error::ErrorCode Soprano::Model::removeAllStatements ( )

Convenience method that clear the Model of all statements


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