/usr/include/soprano/indexfiltermodel.h is in libsoprano-dev 2.7.5+dfsg.1-0ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 | /*
* This file is part of Soprano Project.
*
* Copyright (C) 2007-2008 Sebastian Trueg <trueg@kde.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#ifndef _SOPRANO_INDEX_MODEL_FILTER_H_
#define _SOPRANO_INDEX_MODEL_FILTER_H_
#include "filtermodel.h"
#include "soprano_export.h"
namespace Soprano {
namespace Query {
class Query;
}
/**
* The %Soprano %Index provides a full text search index based on CLucene. It allows
* very fast full text queries against the literal object nodes in a %Soprano Model.
*
* The perfect starting point is IndexFilterModel. Most users will not need more.
*
* In a future version of %Soprano the index will be integrated into the query API,
* allowing for fast full text queries in combination with standard RDF queries.
* At the moment these have to be done separately (see IndexFilterModel::executeQuery()).
*/
namespace Index {
class CLuceneIndex;
class QueryResult;
class IndexFilterModelPrivate;
/**
* \class IndexFilterModel indexfiltermodel.h Soprano/Index/IndexFilterModel
*
* \brief 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@kde.org>
*/
class SOPRANO_INDEX_EXPORT IndexFilterModel : public Soprano::FilterModel
{
public:
/**
* Create a new index model.
*
* \param indexDir The 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.
* \param model The parent model to forward the calls to. If 0 the Model has to
* be set later on with FilterModel::setParentModel.
*/
IndexFilterModel( const QString& indexDir, Soprano::Model* model = 0 );
/**
* Create a new index model.
*
* \param index The index to be used. The filter model will NOT take ownership of
* the index. The caller has to take care of deleting the index.
* \param model The parent model to forward the calls to. If 0 the Model has to
* be set later on with FilterModel::setParentModel.
*/
IndexFilterModel( CLuceneIndex* index, Soprano::Model* model = 0 );
/**
* Destructor.
*/
~IndexFilterModel();
/**
* Retrieve the index used by this index model.
*/
CLuceneIndex* index() const;
/**
* 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.
*/
Soprano::Error::ErrorCode addStatement( const Soprano::Statement &statement );
/**
* Removes a statement.
*
* This will remove the statement from the index and then forward the call to the parent model.
*/
Soprano::Error::ErrorCode removeStatement( const Soprano::Statement &statement );
/**
* Removes statements.
*
* This will remove the statements from the index and then forward the call to the parent model.
*/
Soprano::Error::ErrorCode removeAllStatements( const Soprano::Statement &statement );
/**
* 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).
*
* \param query The query string. This can be a CLucene query in which case the query will
* be passed to CLuceneIndex.
* \param language The query language. Set to Soprano::Query::QueryLanguageUser for
* CLucene queries.
* \param userQueryLanguage If \p language equals Query::QueryLanguageUser
* userQueryLanguage defines the language to use. Use <b>"lucene"</b>
* to perform CLucene queries.
*
* \return 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 <b>"resource"</b> and <b>"score"</b>.
*
* \sa CLuceneIndex::search()
*/
QueryResultIterator executeQuery( const QString& query, Query::QueryLanguage language, const QString& userQueryLanguage = QString() ) const;
/*
* Extract full text matching parts of a %query and replace them with
* results from an index %query.
*
* \param query The query to rewrite.
*
* \return A rewritten query stripped of all full test and regexp matching parts
* and replaced by results from an index query.
*/
// Query::Query evaluateAndRewriteQuery( const Query::Query& query ) const;
/**
* 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.
*
* \param size The number of operations that should be handled in one transaction.
* Set to 1 to disable.
*
* \sa CLuceneIndex::startTransaction, CLuceneIndex::closeTransaction
*/
void setTransactionCacheSize( int size );
/**
* The number of addStatement operations to cache in one transaction.
*
* \sa setTransactionCacheSize
*/
int transactionCacheSize() const;
/**
* 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
*/
void rebuildIndex();
/**
* Optimize the index for search. This makes sense after adding or
* removing a large number of statements.
*
* \sa CLuceneIndex::optimize
*
* \since 2.2
*/
void optimizeIndex();
/**
* 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.
*
* \param predicate The predicate that should only be indexed
* but not stored in the underlying Model.
*
* \sa indexOnlyPredicates, setIndexOnlyPredicates
*
* \since 2.1
*/
void addIndexOnlyPredicate( const QUrl& predicate );
/**
* 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.
*
* \param predicates A list of predicates that should only be indexed
* but not stored in the underlying Model.
*
* \sa indexOnlyPredicates, addIndexOnlyPredicate
*
* \since 2.1
*/
void setIndexOnlyPredicates( const QList<QUrl>& predicates );
/**
* 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.
*
* \return A list of predicates that will only be indexed but not
* stored in the underlying Model.
*
* \sa addIndexOnlyPredicate, setIndexOnlyPredicates
*
* \since 2.1
*/
QList<QUrl> indexOnlyPredicates() const;
/**
* Add a predicate which should be indexed even if the object is a resource.
* See setForceIndexPredicates for a detailed explanation.
*
* \param predicate The predicate that should be indexed
* in any case.
*
* \sa forceIndexPredicates, setForceIndexPredicates
*
* \since 2.2
*/
void addForceIndexPredicate( const QUrl& predicate );
/**
* 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:
*
* \code
* model->executeQuery( QString( "foobar AND %1:%2" )
* .arg( encodeUriForLuceneQuery( RDF::type() ) )
* .arg( encodeUriForLuceneQuery( myType ) ),
* Query::QueryLanguageUser,
* "lucene" );
* \endcode
*
* \param predicates The predicates that should be indexed
* in any case.
*
* \sa forceIndexPredicates, addForceIndexPredicate
*
* \since 2.2
*/
void setForceIndexPredicates( const QList<QUrl>& predicates );
/**
* See setForceIndexPredicates for a detailed explanation.
*
* \return A list of predicates that will be indexed even if the object
* is not a literal.
*
* \sa addForceIndexPredicate, setForceIndexPredicates
*
* \since 2.2
*/
QList<QUrl> forceIndexPredicates() const;
/**
* 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.
*
* \param value The string to be encoded.
*
* \return An encoded and escaped string representation of the
* provided string.
*
* \sa encodeUriForLuceneQuery
*
* \since 2.2
*/
static QString encodeStringForLuceneQuery( const QString& value );
/**
* 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.
*
* \param uri The URI to be encoded.
*
* \return An encoded and escaped string representation of the URI.
*
* \sa encodeStringForLuceneQuery
*
* \since 2.2
*/
static QString encodeUriForLuceneQuery( const QUrl& uri );
using FilterModel::addStatement;
using FilterModel::removeStatement;
using FilterModel::removeAllStatements;
private:
IndexFilterModelPrivate* const d;
};
}
}
#endif
|