2 This file is part of the Nepomuk KDE project.
3 Copyright (C) 2007 Sebastian Trueg <trueg@kde.org>
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License version 2 as published by the Free Software Foundation.
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 Boston, MA 02110-1301, USA.
20 #ifndef _NEPOMUK_SEARCH_THREAD_H_
21 #define _NEPOMUK_SEARCH_THREAD_H_
23 #include <QtCore/QThread>
24 #include <QtCore/QHash>
25 #include <QtCore/QUrl>
26 #include <QtCore/QPair>
35 class QueryResultIterator
;
50 SearchNode( const Term
& t
, Type tt
= Unknown
, const QList
<SearchNode
>& sub
= QList
<SearchNode
>() )
58 QList
<SearchNode
> subNodes
;
61 class SearchThread
: public QThread
66 SearchThread( QObject
* parent
= 0 );
70 * Use instead of QThread::start()
72 void query( const Query
& query
, double cutOffScore
);
75 double cutOffScore() const { return m_cutOffScore
; }
78 void newResult( const Nepomuk::Search::Result
& result
);
85 * Makes sure each contains or euality term has a property set instead of
86 * a fuzzy field name. However, nonexisting fields will not be changed!
88 * If a field matches multiple properties an OR term will be constructed to include
91 * Works recursively on all term types.
93 Nepomuk::Search::Term
resolveFields( const Term
& term
);
96 * Resolves the values in the contains and equality terms.
97 * This means that terms that refer to properties that have resource ranges
98 * are replaced by terms that name the actual resources.
100 * Be aware that resolveFields needs to be run before this method.
102 * Works recursively on all term types.
104 Nepomuk::Search::Term
resolveValues( const Term
& term
);
107 * Optimizes a query, i.e. combines OR and AND terms where possible.
109 Nepomuk::Search::Term
optimize( const Term
& term
);
112 * Try to split the query into two (or more) subqueries, one of which will be
113 * executed against the lucene index and one against the soprano store.
115 SearchNode
splitLuceneSparql( const Term
& term
);
117 QList
<QUrl
> matchFieldName( const QString
& field
);
118 QHash
<QUrl
, Result
> search( const SearchNode
& node
, double baseScore
, bool reportResults
= false );
119 QHash
<QUrl
, Result
> andSearch( const QList
<SearchNode
>& terms
, double baseScore
, bool reportResults
= false );
120 QHash
<QUrl
, Result
> orSearch( const QList
<SearchNode
>& terms
, double baseScore
, bool reportResults
= false );
121 QHash
<QUrl
, Nepomuk::Search::Result
> sparqlQuery( const QString
& query
, double baseScore
, bool reportResults
);
122 QHash
<QUrl
, Nepomuk::Search::Result
> luceneQuery( const QString
& query
, double baseScore
, bool reportResults
);
124 QString
buildRequestPropertyVariableList() const;
125 QString
buildRequestPropertyPatterns() const;
126 Nepomuk::Search::Result
extractResult( const Soprano::QueryResultIterator
& it
) const;
127 void fetchRequestPropertiesForResource( Result
& uri
);
129 QString
createSparqlQuery( const SearchNode
& node
);
132 double m_cutOffScore
;