~ubuntu-branches/ubuntu/gutsy/soprano/gutsy

« back to all changes in this revision

Viewing changes to index/indexfiltermodel.h

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2007-10-12 14:43:48 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20071012144348-yajzi51v4k23ahxf
Tags: 1.95.0~beta2-1ubuntu1
* Sync with Debian
* Add versioned build-dep on raptor

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * This file is part of Soprano Project.
 
3
 *
 
4
 * Copyright (C) 2007 Sebastian Trueg <trueg@kde.org>
 
5
 *
 
6
 * This library is free software; you can redistribute it and/or
 
7
 * modify it under the terms of the GNU Library General Public
 
8
 * License as published by the Free Software Foundation; either
 
9
 * version 2 of the License, or (at your option) any later version.
 
10
 *
 
11
 * This library is distributed in the hope that it will be useful,
 
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
14
 * Library General Public License for more details.
 
15
 *
 
16
 * You should have received a copy of the GNU Library General Public License
 
17
 * along with this library; see the file COPYING.LIB.  If not, write to
 
18
 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 
19
 * Boston, MA 02110-1301, USA.
 
20
 */
 
21
 
 
22
#ifndef _SOPRANO_INDEX_MODEL_FILTER_H_
 
23
#define _SOPRANO_INDEX_MODEL_FILTER_H_
 
24
 
 
25
#include "filtermodel.h"
 
26
#include "soprano_export.h"
 
27
 
 
28
namespace Soprano {
 
29
 
 
30
    namespace Query {
 
31
        class Query;
 
32
    }
 
33
 
 
34
    namespace Index {
 
35
 
 
36
        class CLuceneIndex;
 
37
        class QueryResult;
 
38
 
 
39
        /**
 
40
         * \class IndexFilterModel indexfiltermodel.h Soprano/Index/IndexFilterModel
 
41
         *
 
42
         * \brief The IndexFilterModel provides a full text index around any Soprano Model.
 
43
         *
 
44
         * All statements with a literal object will be indexed.
 
45
         *
 
46
         * \author Sebastian Trueg <trueg@kde.org>
 
47
         */
 
48
        class SOPRANO_INDEX_EXPORT IndexFilterModel : public Soprano::FilterModel
 
49
        {
 
50
        public:
 
51
            /**
 
52
             * Create a new index model.
 
53
             *
 
54
             * \param indexDir The directory where the index should be stored. If the
 
55
             * directory already contains an index, it will be used. Otherwise a new
 
56
             * one will be created.
 
57
             * \param model The parent model to forward the calls to. If 0 the Model has to
 
58
             * be set later on with FilterModel::setParentModel.
 
59
             */
 
60
            IndexFilterModel( const QString& indexDir, Soprano::Model* model = 0 );
 
61
 
 
62
            /**
 
63
             * Create a new index model.
 
64
             *
 
65
             * \param index The index to be used. The filter model will NOT take ownership of
 
66
             * the index. The caller has to take care of deleting the index.
 
67
             * \param model The parent model to forward the calls to. If 0 the Model has to
 
68
             * be set later on with FilterModel::setParentModel.
 
69
             */
 
70
            IndexFilterModel( CLuceneIndex* index, Soprano::Model* model = 0 );
 
71
            
 
72
            /**
 
73
             * Destructor.
 
74
             */
 
75
            ~IndexFilterModel();
 
76
 
 
77
            /**
 
78
             * Retrieve the index used by this index model.
 
79
             */
 
80
            CLuceneIndex* index() const;
 
81
 
 
82
            /**
 
83
             * Adds a new statement.
 
84
             *
 
85
             * This will index the statement and then forward the call to the parent model.
 
86
             */
 
87
            Soprano::Error::ErrorCode addStatement( const Soprano::Statement &statement );
 
88
 
 
89
            /**
 
90
             * Removes a statement.
 
91
             *
 
92
             * This will remove the statement from the index and then forward the call to the parent model.
 
93
             */
 
94
            Soprano::Error::ErrorCode removeStatement( const Soprano::Statement &statement );
 
95
 
 
96
            /**
 
97
             * Removes statements.
 
98
             *
 
99
             * This will remove the statements from the index and then forward the call to the parent model.
 
100
             */
 
101
            Soprano::Error::ErrorCode removeAllStatements( const Soprano::Statement &statement );
 
102
 
 
103
            /**
 
104
             * The IndexFilterModel is currently based on CLucene. While the index itself is available
 
105
             * via index() and allows querying via CLucene queries it is not available over the 
 
106
             * Soprano::Client interface.
 
107
             * Thus, CLucene queries are supported through this method and will return QueryHit objects
 
108
             * wrapped in a QueryResultIterator.
 
109
             *
 
110
             * Future versions of %Soprano will support querying the index through the Soprano::Query API
 
111
             * (still unfinished and unstable).
 
112
             *
 
113
             * \param query The query string. This can be a CLucene query in which case the query will
 
114
             *              be passed to CLuceneIndex.
 
115
             * \param language The query language. Set to Soprano::Query::QUERY_LANGUAGE_USER for
 
116
             *                 CLucene queries.
 
117
             * \param userQueryLanguage If \p language equals Query::QUERY_LANGUAGE_USER
 
118
             *                          userQueryLanguage defines the language to use. Use <b>"lucene"</b>
 
119
             *                          to perform CLucene queries.
 
120
             *
 
121
             * \return An iterator over all results matching the query, 
 
122
             * on error an invalid iterator is returned. In case of a CLucene query the iterator will
 
123
             * wrap a set of QueryHit objects through the bindings <b>"resource"</b> and <b>"score"</b>.
 
124
             *
 
125
             * \sa CLuceneIndex::search()
 
126
             */
 
127
            QueryResultIterator executeQuery( const QString& query, Query::QueryLanguage language, const QString& userQueryLanguage = QString() ) const;
 
128
 
 
129
            /**
 
130
             * Extract full text matching parts of a %query and replace them with
 
131
             * results from an index %query.
 
132
             *
 
133
             * \param query The query to rewrite.
 
134
             *
 
135
             * \return A rewritten query stripped of all full test and regexp matching parts
 
136
             * and replaced by results from an index query.
 
137
             */
 
138
//          Query::Query evaluateAndRewriteQuery( const Query::Query& query ) const;
 
139
 
 
140
        private:
 
141
            class Private;
 
142
            Private* const d;
 
143
        };
 
144
    }
 
145
}
 
146
 
 
147
#endif