delay a few things on startup, such as setting the visibility mode, which ensures...
[personal-kdebase.git] / runtime / nepomuk / services / queryservice / searchthread.h
blobab9b9d66219771c10bce90eb614530a4e755a1cd
1 /*
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>
28 #include "query.h"
29 #include "term.h"
30 #include "result.h"
34 namespace Soprano {
35 class QueryResultIterator;
38 namespace Nepomuk {
39 namespace Search {
41 class SearchNode
43 public:
44 enum Type {
45 Unknown,
46 Lucene,
47 Sparql
50 SearchNode( const Term& t, Type tt = Unknown, const QList<SearchNode>& sub = QList<SearchNode>() )
51 : term(t),
52 type(tt),
53 subNodes(sub) {
56 Term term;
57 Type type;
58 QList<SearchNode> subNodes;
61 class SearchThread : public QThread
63 Q_OBJECT
65 public:
66 SearchThread( QObject* parent = 0 );
67 ~SearchThread();
69 /**
70 * Use instead of QThread::start()
72 void query( const Query& query, double cutOffScore );
73 void cancel();
75 double cutOffScore() const { return m_cutOffScore; }
77 signals:
78 void newResult( const Nepomuk::Search::Result& result );
80 protected:
81 void run();
83 private:
84 /**
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
89 * them all.
91 * Works recursively on all term types.
93 Nepomuk::Search::Term resolveFields( const Term& term );
95 /**
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 );
131 Query m_searchTerm;
132 double m_cutOffScore;
134 // status
135 int m_numResults;
136 bool m_canceled;
141 #endif