|
1 /* |
|
2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Qt search APIs |
|
15 * |
|
16 */ |
|
17 |
|
18 #ifndef _CPIXSEARCHER_H |
|
19 #define _CPIXSEARCHER_H |
|
20 |
|
21 //Uncomment the following line to enable performance measurements |
|
22 //#define OST_TRACE_COMPILER_IN_USE |
|
23 |
|
24 #ifdef OST_TRACE_COMPILER_IN_USE |
|
25 |
|
26 #include <qdatetime.h> |
|
27 #include <qdebug.h> |
|
28 #define PERF_SEARCH_START_TIMER searchTimer.start(); |
|
29 #define PERF_SEARCH_RESTART_TIMER searchTimer.restart(); |
|
30 #define PERF_SEARCH_ENDLOG qDebug() << "Search QT API took: " << searchTimer.elapsed() << "msec"; |
|
31 |
|
32 #define PERF_GETDOC_START_TIMER getDocumentTimer.start(); |
|
33 #define PERF_GETDOC_RESTART_TIMER getDocumentTimer.restart(); |
|
34 #define PERF_GETDOC_ENDLOG qDebug() << "Search QT API took: " << getDocumentTimer.elapsed() << "msec"; |
|
35 |
|
36 #define PERF_TIME_NOW(message) qDebug() << "Search QT API: " << QString(message) << ": " << QTime::currentTime().toString("hh:mm:ss.zzz"); |
|
37 |
|
38 #else |
|
39 |
|
40 #define PERF_SEARCH_START_TIMER |
|
41 #define PERF_SEARCH_RESTART_TIMER |
|
42 #define PERF_SEARCH_ENDLOG |
|
43 #define PERF_GETDOC_START_TIMER |
|
44 #define PERF_GETDOC_RESTART_TIMER |
|
45 #define PERF_GETDOC_ENDLOG |
|
46 #define PERF_TIME_NOW(message) |
|
47 |
|
48 #endif |
|
49 |
|
50 /** |
|
51 * @file |
|
52 * @ingroup Search Client API fpr Qt Clients |
|
53 * @brief Contains CCPixSearcher used for searching |
|
54 */ |
|
55 |
|
56 #ifdef BUILD_DLL |
|
57 #define DLL_EXPORT Q_DECL_EXPORT |
|
58 #else |
|
59 #define DLL_EXPORT Q_DECL_IMPORT |
|
60 #endif |
|
61 |
|
62 #include <QObject> |
|
63 #include <cpixcommon.h> |
|
64 |
|
65 //forward declarations |
|
66 class CpixDocument; |
|
67 class CpixSearcherPrivate; |
|
68 |
|
69 // CLASS DECLARATION |
|
70 /** |
|
71 * @brief Used for searching. |
|
72 * @ingroup Qt Search Client API |
|
73 * Link against: cpixsearch.lib |
|
74 * |
|
75 * An instance of CpixSearcher is used to commit search operations. |
|
76 * |
|
77 * Example code: |
|
78 * |
|
79 * Usecase 1: Sync calls. |
|
80 * \code |
|
81 * CpixSearcher* searcher = CpixSearcher::newInstance("root"); |
|
82 * if(searcher){ |
|
83 * int hitCount = searcher->search("search for me"); |
|
84 * for(int i=0; i<hitCount; i++) { |
|
85 * CpixDocument* doc = document(0); |
|
86 * // do something with doc. |
|
87 * delete doc; |
|
88 * } |
|
89 * } |
|
90 * \endcode |
|
91 * |
|
92 * Usecase 2: Sync calls with explicit SetDatabase(). |
|
93 * \code |
|
94 * CpixSearcher* searcher = CpixSearcher::newInstance(); |
|
95 * searcher->SetDatabase("root"); |
|
96 * int hitCount = searcher->search("search for me"); |
|
97 * for(int i=0; i<hitCount; i++) { |
|
98 * try{ |
|
99 * CpixDocument* doc = document(i); |
|
100 * // do something with doc. |
|
101 * delete doc; |
|
102 * catch(...){ |
|
103 * //Do Cleanup |
|
104 * } |
|
105 * } |
|
106 * \endcode |
|
107 * |
|
108 * Usecase 3: Async Calls |
|
109 * \code |
|
110 * |
|
111 * iCurrentDocumentCount = 0; |
|
112 * |
|
113 * CpixSearcher* searcher = CpixSearcher::newInstance("root"); |
|
114 * connect(searcher, SIGNAL(handleSearchResults(int,int)), this, SLOT(ClientHandleSearchCompleteSlot(int,int)) ); |
|
115 * connect(searcher, SIGNAL(handleDocument(int,CpixDocument*)), this, SLOT(ClientHandleGetDocumentCompleteSlot(int,CpixDocument*)) ); |
|
116 * int hitCount = searcher->search("search for me"); |
|
117 * GetDocumentAsync( iCurrentDocumentCount++ ); |
|
118 * |
|
119 * ClientClass::ClientHandleGetDocumentCompleteSlot(int aError, CpixDocument* aDocument){ |
|
120 * if( KErrNone != aError ){ |
|
121 * //do something with aDocument |
|
122 * } |
|
123 * documentAsync( iCurrentDocumentCount++ ); //Now get the next document. |
|
124 * } |
|
125 * |
|
126 * \endcode |
|
127 * |
|
128 */ |
|
129 class DLL_EXPORT CpixSearcher: public QObject |
|
130 { |
|
131 Q_OBJECT |
|
132 public: |
|
133 /** |
|
134 * Constructor. |
|
135 * Creates a CpixSearcher object and return a pointer to the created object. |
|
136 * @return A pointer to the created instance of CCPixSearcher. |
|
137 * |
|
138 * @note After using this constructor, the client has to mandatorily call |
|
139 * SetDatabase() before invoking any search. |
|
140 */ |
|
141 static CpixSearcher* newInstance(); |
|
142 |
|
143 /** |
|
144 * Overloaded constructor |
|
145 * Creates a CCPixSearcher object and return a pointer to the created object. |
|
146 * If this constructor is used, the client can directly invoke Search without |
|
147 * the need to call SetDatabase. |
|
148 * @param aBaseAppClass The baseAppClass on which to invoke searches on. |
|
149 * @param aDefaultSearchField Default field where the keywords are searched from. |
|
150 * @return A pointer to the created instance of CCPixSearcher. |
|
151 */ |
|
152 static CpixSearcher* newInstance( QString aBaseAppClass, QString aDefaultSearchField=NULL ); |
|
153 |
|
154 /** |
|
155 * Destructor. |
|
156 */ |
|
157 ~CpixSearcher(); |
|
158 |
|
159 /** |
|
160 * Synchronously set (or change the database, if already set) on which to invoke subsequent searches. |
|
161 * @param aBaseAppClass baseAppClass whose corresponding database is to be opened. |
|
162 */ |
|
163 void setDatabase(QString aBaseAppClass) THROWS_EXCEPTION; |
|
164 |
|
165 /** |
|
166 * Asynchronously set (or change the database, if already set) on which to invoke subsequent searches. |
|
167 * @param aBaseAppClass baseAppClass whose corresponding database is to be opened. |
|
168 * |
|
169 * @note Client is notified on completion of this call via HandleDatabaseSet signal. |
|
170 */ |
|
171 void setDatabaseAsync(QString aBaseAppClass) THROWS_EXCEPTION; |
|
172 |
|
173 /** |
|
174 * Syncronously search for aSearchString. |
|
175 * @param aSearchString keywords to be searched for. |
|
176 * @param aDefaultSearchField Default field where the keywords are searched from. |
|
177 * @return Estimated number of documents containing aSearchString. |
|
178 */ |
|
179 int search(QString aSearchString, QString aDefaultSearchField=NULL) THROWS_EXCEPTION; |
|
180 |
|
181 /** |
|
182 * Asyncronously search for aSearchString. |
|
183 * @param aSearchString keywords to be searched for. |
|
184 * @param aDefaultSearchField Default field where the keywords are searched from. |
|
185 * @return Estimated number of documents containing aSearchString. |
|
186 * |
|
187 * @note Client is notified on completion of this call via HandleSearchResults signal. |
|
188 */ |
|
189 void searchAsync(QString aSearchString, QString aDefaultSearchField=NULL) THROWS_EXCEPTION; |
|
190 |
|
191 /** |
|
192 * Synchronously get the document with index aIndex. |
|
193 * @param aIndex Index of document to be retrieved |
|
194 * @return A pointer to CpixDocument that has been retrieved. Null on error. |
|
195 * |
|
196 * @note This should be called only after the synchronous search call has returned |
|
197 * and aIndex should be between 0 and estimated count returned by Search(). |
|
198 */ |
|
199 CpixDocument* document(int aIndex) THROWS_EXCEPTION; |
|
200 |
|
201 /** |
|
202 * Asynchronously get the document with index aIndex. |
|
203 * @param aIndex Index of document to be retrieved |
|
204 * @return A pointer to CpixDocument that has been retrieved. Null on error. |
|
205 * |
|
206 * @note This should be called only after the synchronous search call has returned |
|
207 * and aIndex should be between 0 and estimated count returned by Search(). |
|
208 */ |
|
209 void documentAsync(int aIndex) THROWS_EXCEPTION; |
|
210 |
|
211 /** |
|
212 * Cancels any outstanding searches. |
|
213 */ |
|
214 void cancelSearch(); |
|
215 |
|
216 signals: |
|
217 /** |
|
218 * Notify completion of SetDatabaseAsyc |
|
219 * @param aError Completion (error) code of SetDatabaseAsync |
|
220 */ |
|
221 void handleDatabaseSet(int aError); |
|
222 |
|
223 /** |
|
224 * Notify completion of SearchAsyc |
|
225 * @param aError Completion (error) code of SearchAsyc |
|
226 * @param aEstimatedResultCount Estimated number of documents found after SearchAsync |
|
227 */ |
|
228 void handleSearchResults(int aError, int aEstimatedResultCount); |
|
229 |
|
230 /** |
|
231 * Notify completion of GetDatabaseAsyc |
|
232 * @param aError Completion (error) code of GetDatabaseAsyc |
|
233 * @param aDocument The requested document. |
|
234 */ |
|
235 void handleDocument(int aError, CpixDocument* aDocument); |
|
236 |
|
237 private: |
|
238 /** |
|
239 * Defaul constructor. |
|
240 * Creates a CpixSearcher object and return a pointer to the created object. |
|
241 * @return A pointer to the created instance of CCPixSearcher. |
|
242 */ |
|
243 CpixSearcher(); |
|
244 |
|
245 CpixSearcherPrivate* const iPvtImpl; |
|
246 Q_DECLARE_PRIVATE_D( iPvtImpl, CpixSearcher ) |
|
247 |
|
248 #ifdef OST_TRACE_COMPILER_IN_USE |
|
249 QTime searchTimer; |
|
250 QTime getDocumentTimer; |
|
251 #endif |
|
252 }; |
|
253 |
|
254 #endif //_CPIXSEARCHER_H |