author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Wed, 15 Sep 2010 11:56:55 +0300 | |
branch | RCL_3 |
changeset 74 | 6b5524b4f673 |
parent 63 | f4a778e096c2 |
child 85 | 38bb213f60ba |
permissions | -rw-r--r-- |
63 | 1 |
/* |
2 |
* Copyright (c) 2007 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: Supports initial search feature. |
|
15 |
* |
|
16 |
*/ |
|
17 |
||
18 |
// INCLUDES |
|
19 |
#include "FindUtilChineseECE.h" |
|
20 |
#include "CPcsAlgorithm2MultiSearchHelper.h" |
|
21 |
#include "CPcsAlgorithm2Utils.h" |
|
22 |
#include "CPcsDefs.h" |
|
23 |
#include <collate.h> |
|
24 |
#include <biditext.h> |
|
25 |
||
26 |
||
27 |
// ============================== MEMBER FUNCTIONS ============================ |
|
28 |
||
29 |
// ---------------------------------------------------------------------------- |
|
30 |
// CPcsAlgorithm2MultiSearchHelper::NewL |
|
31 |
// Two Phase Construction |
|
32 |
// ---------------------------------------------------------------------------- |
|
33 |
CPcsAlgorithm2MultiSearchHelper* CPcsAlgorithm2MultiSearchHelper::NewL(CPcsAlgorithm2* aAlgorithm) |
|
34 |
{ |
|
35 |
PRINT ( _L("Enter CPcsAlgorithm2MultiSearchHelper::NewL") ); |
|
36 |
||
37 |
CPcsAlgorithm2MultiSearchHelper* self = new (ELeave) CPcsAlgorithm2MultiSearchHelper(); |
|
38 |
CleanupStack::PushL(self); |
|
39 |
self->ConstructL(aAlgorithm); |
|
40 |
CleanupStack::Pop(self); |
|
41 |
||
42 |
PRINT ( _L("End CPcsAlgorithm2MultiSearchHelper::NewL") ); |
|
43 |
||
44 |
return self; |
|
45 |
} |
|
46 |
||
47 |
// ---------------------------------------------------------------------------- |
|
48 |
// CPcsAlgorithm2MultiSearchHelper::CPcsAlgorithm2MultiSearchHelper |
|
49 |
// Two Phase Construction |
|
50 |
// ---------------------------------------------------------------------------- |
|
51 |
CPcsAlgorithm2MultiSearchHelper::CPcsAlgorithm2MultiSearchHelper() |
|
52 |
{ |
|
53 |
PRINT ( _L("Enter CPcsAlgorithm2MultiSearchHelper::CPcsAlgorithm2") ); |
|
54 |
PRINT ( _L("End CPcsAlgorithm2MultiSearchHelper::CPcsAlgorithm2") ); |
|
55 |
} |
|
56 |
||
57 |
// ---------------------------------------------------------------------------- |
|
58 |
// CPcsAlgorithm2MultiSearchHelper::ConstructL |
|
59 |
// Two Phase Construction |
|
60 |
// ---------------------------------------------------------------------------- |
|
61 |
void CPcsAlgorithm2MultiSearchHelper::ConstructL(CPcsAlgorithm2* aAlgorithm) |
|
62 |
{ |
|
63 |
PRINT ( _L("Enter CPcsAlgorithm2MultiSearchHelper::ConstructL") ); |
|
64 |
||
65 |
iAlgorithm = aAlgorithm; |
|
66 |
iKeyMap = iAlgorithm->GetKeyMap(); |
|
67 |
iMaxCount = 0; |
|
68 |
||
69 |
PRINT ( _L("End CPcsAlgorithm2MultiSearchHelper::ConstructL") ); |
|
70 |
} |
|
71 |
||
72 |
// ---------------------------------------------------------------------------- |
|
73 |
// CPcsAlgorithm2MultiSearchHelper::~CPcsAlgorithm2MultiSearchHelper |
|
74 |
// Destructor |
|
75 |
// ---------------------------------------------------------------------------- |
|
76 |
CPcsAlgorithm2MultiSearchHelper::~CPcsAlgorithm2MultiSearchHelper() |
|
77 |
{ |
|
78 |
PRINT ( _L("Enter CPcsAlgorithm2MultiSearchHelper::~CPcsAlgorithm2MultiSearchHelper") ); |
|
79 |
iMultiSearchResultsArr.ResetAndDestroy(); |
|
80 |
PRINT ( _L("End CPcsAlgorithm2MultiSearchHelper::~CPcsAlgorithm2MultiSearchHelper") ); |
|
81 |
} |
|
82 |
||
83 |
// ---------------------------------------------------------------------------- |
|
84 |
// CPcsAlgorithm2MultiSearchHelper::SearchMultiL |
|
85 |
// Initial search feature. |
|
86 |
// Flow of steps in initial search is explained below. |
|
87 |
// (1) Extract the pool elements corresponding to one of the queries. |
|
88 |
// (2) Always the first query is used here. |
|
89 |
// (3) Get pool elements from all caches corresponding to the data stores. |
|
90 |
// (4) Convert each query to mode specific form. |
|
91 |
// (5) Parse each data element. |
|
92 |
// (6) Check for every search query atleast one data element matches. |
|
93 |
// (7) If NOT ignore the result. |
|
94 |
// (8) If so perform an additional check that number of data matches is |
|
95 |
// atleast equal to number of search queries. This will ensure that same |
|
96 |
// data element has not matched for multiple queries. |
|
97 |
// (9) Now include the element in the result. |
|
98 |
// ---------------------------------------------------------------------------- |
|
99 |
void CPcsAlgorithm2MultiSearchHelper::SearchMultiL(const CPsSettings& aSettings, |
|
100 |
RPointerArray<CPsQuery>& aPsQuery, |
|
101 |
TBool aIsSearchInGroup, |
|
102 |
const RArray<TInt>& aContactsInGroup, |
|
103 |
RPointerArray<CPsData>& aSearchResults, |
|
104 |
RPointerArray<CPsPattern>& aSearchSeqs) |
|
105 |
{ |
|
106 |
PRINT ( _L("Enter CPcsAlgorithm2MultiSearchHelper::SearchMultiL") ); |
|
107 |
||
108 |
//__LATENCY_MARK ( _L("CPcsAlgorithm2MultiSearchHelper::SearchMultiL") ); |
|
109 |
||
110 |
PRINTQUERYLIST ( _L("CPcsAlgorithm2MultiSearchHelper::SearchMultiL: "), aPsQuery ); |
|
111 |
||
112 |
iMaxCount = aSettings.MaxResults(); |
|
113 |
// Create CPcsAlgorithm2FilterHelper object to be used for filtering the results |
|
114 |
TSortType sortType = aSettings.GetSortType(); |
|
115 |
CPcsAlgorithm2FilterHelper* filterHelper = CPcsAlgorithm2FilterHelper::NewL(sortType); |
|
116 |
CleanupStack::PushL( filterHelper ); |
|
117 |
RPointerArray<CPcsPoolElement> elements; |
|
118 |
CleanupClosePushL( elements ); |
|
119 |
||
120 |
iMultiSearchResultsArr.ResetAndDestroy(); |
|
121 |
||
122 |
// Get the data stores |
|
123 |
RPointerArray<TDesC> dataStores; |
|
124 |
CleanupResetAndDestroyPushL( dataStores ); |
|
125 |
aSettings.SearchUrisL(dataStores); |
|
126 |
||
127 |
// Get the required display fields from the client |
|
128 |
RArray<TInt> requiredDataFields; |
|
129 |
CleanupClosePushL( requiredDataFields ); |
|
130 |
aSettings.DisplayFieldsL(requiredDataFields); |
|
131 |
||
132 |
// Search from cache based on first character of 1st item in query list |
|
133 |
const CPsQueryItem& firstCharItem = aPsQuery[0]->GetItemAtL(0); |
|
134 |
TInt cachePoolId = iKeyMap->PoolIdForCharacter( firstCharItem.Character(), firstCharItem.Mode() ); |
|
135 |
||
136 |
// Get the elements from all the databases |
|
137 |
const TInt dataStoresCount = dataStores.Count(); |
|
138 |
for (TInt dsIndex = 0; dsIndex < dataStoresCount; dsIndex++) |
|
139 |
{ |
|
140 |
RPointerArray<CPsData> *temp = new (ELeave) RPointerArray<CPsData> (); |
|
141 |
iMultiSearchResultsArr.Append(temp); |
|
142 |
||
143 |
// Get the contents for this data store |
|
144 |
TInt arrayIndex = iAlgorithm->GetCacheIndex(*(dataStores[dsIndex])); |
|
145 |
if (arrayIndex < 0) |
|
146 |
{ |
|
147 |
continue; |
|
148 |
} |
|
149 |
CPcsCache* cache = iAlgorithm->GetCache(arrayIndex); |
|
150 |
cache->GetContactsForKeyL(cachePoolId, elements); |
|
151 |
||
152 |
// Get the supported data fields for this data store |
|
153 |
RArray<TInt> supportedDataFields; |
|
154 |
CleanupClosePushL( supportedDataFields ); |
|
155 |
cache->GetDataFields(supportedDataFields); |
|
156 |
||
157 |
// Get the filtered data fields for this data store |
|
158 |
TUint8 filteredDataMatch = CPcsAlgorithm2Utils::FilterDataFieldsL( |
|
159 |
requiredDataFields, supportedDataFields); |
|
160 |
||
161 |
// Filter the results now |
|
162 |
FilterResultsMultiL(filterHelper, |
|
163 |
elements, |
|
164 |
aPsQuery, |
|
165 |
filteredDataMatch, |
|
166 |
aIsSearchInGroup, |
|
167 |
aContactsInGroup); |
|
168 |
||
169 |
// If alphabetical sorting, get the results for this datastore |
|
170 |
if (sortType == EAlphabetical) |
|
171 |
{ |
|
172 |
filterHelper->GetResults(*(iMultiSearchResultsArr[dsIndex])); |
|
173 |
} |
|
174 |
||
175 |
elements.Reset(); |
|
176 |
CleanupStack::PopAndDestroy( &supportedDataFields ); // Close |
|
177 |
} |
|
178 |
CleanupStack::PopAndDestroy( &requiredDataFields ); // Close |
|
179 |
CleanupStack::PopAndDestroy( &dataStores ); // ResetAndDestroy |
|
180 |
||
181 |
// If alphabetical sorting, merge the result sets of all datastores |
|
182 |
if (sortType == EAlphabetical) |
|
183 |
{ |
|
184 |
// Form the complete searchResults array |
|
185 |
CPcsAlgorithm2Utils::FormCompleteSearchResultsL(iMultiSearchResultsArr, |
|
186 |
aSearchResults); |
|
187 |
} |
|
188 |
else |
|
189 |
{ |
|
190 |
// Results are already sorted patternbased |
|
191 |
filterHelper->GetResults(aSearchResults); |
|
192 |
} |
|
193 |
||
194 |
// Get the sorted match sequence list |
|
195 |
filterHelper->GetPatternsL(aSearchSeqs); |
|
196 |
||
197 |
PRINT1 ( _L("Number of search results = %d"), aSearchResults.Count() ); |
|
198 |
||
199 |
// Cleanup |
|
200 |
for (TInt i = 0; i < iMultiSearchResultsArr.Count(); i++) |
|
201 |
{ |
|
202 |
iMultiSearchResultsArr[i]->Reset(); |
|
203 |
delete iMultiSearchResultsArr[i]; |
|
204 |
iMultiSearchResultsArr[i] = NULL; |
|
205 |
} |
|
206 |
||
207 |
iMultiSearchResultsArr.Reset(); |
|
208 |
CleanupStack::PopAndDestroy( &elements ); // Close |
|
209 |
CleanupStack::PopAndDestroy( filterHelper ); |
|
210 |
||
211 |
//__LATENCY_MARKEND ( _L("CPcsAlgorithm2MultiSearchHelper::SearchMultiL") ); |
|
212 |
||
213 |
PRINT ( _L("End CPcsAlgorithm2MultiSearchHelper::SearchMultiL") ); |
|
214 |
} |
|
215 |
||
216 |
// ---------------------------------------------------------------------------- |
|
217 |
// CPcsAlgorithm1MultiSearchHelper::SearchMatchSeqMultiL |
|
218 |
// Function adds matches, and locations based on multi query, and data |
|
219 |
// Duplicate locations are allowed (as they are removed later anyway) |
|
220 |
// Post condition locations in index order |
|
221 |
// ---------------------------------------------------------------------------- |
|
222 |
void CPcsAlgorithm2MultiSearchHelper::SearchMatchSeqMultiL( RPointerArray<CPsQuery>& aPsQuery, |
|
223 |
const TDesC& aData, |
|
224 |
RPointerArray<TDesC>& aMatchSeq, |
|
225 |
RArray<TPsMatchLocation>& aMatchLocation ) |
|
226 |
{ |
|
227 |
PRINT ( _L("Enter CPcsAlgorithm2MultiSearchHelper::SearchMatchSeqMultiL") ); |
|
228 |
||
229 |
TLex lex(aData); |
|
230 |
while ( !lex.Eos() ) // Search thru all words |
|
231 |
{ |
|
232 |
TPtrC currentWord = lex.NextToken(); // next word |
|
233 |
||
234 |
const TInt psQueryCount = aPsQuery.Count(); |
|
235 |
for ( TInt queryIndex = 0; queryIndex < psQueryCount; ++queryIndex ) |
|
236 |
{ |
|
237 |
CPsQuery* currentQuery = aPsQuery[queryIndex]; |
|
238 |
||
239 |
RArray<TInt> matchPos; |
|
240 |
CleanupClosePushL( matchPos ); |
|
241 |
RArray<TInt> matchLen; |
|
242 |
CleanupClosePushL( matchLen ); |
|
243 |
||
244 |
if ( iAlgorithm->FindUtilECE()->MatchRefineL( currentWord, *currentQuery, matchPos, matchLen, ETrue ) ) |
|
245 |
{ |
|
246 |
// Some matches found. Add all of them to result array. |
|
247 |
ASSERT( matchPos.Count() == matchLen.Count() ); |
|
248 |
||
249 |
TInt wordStartPos = lex.Offset() - currentWord.Length(); |
|
250 |
const TInt matchPosCount = matchPos.Count(); |
|
251 |
for ( TInt i = 0 ; i < matchPosCount; ++i ) |
|
252 |
{ |
|
253 |
TPsMatchLocation newLocation = { wordStartPos + matchPos[i], matchLen[i], |
|
254 |
TBidiText::TextDirectionality(currentWord) }; |
|
255 |
aMatchLocation.AppendL( newLocation ); |
|
256 |
||
257 |
TPtrC matchPart = currentWord.Mid( matchPos[i], matchLen[i] ); |
|
258 |
CPcsAlgorithm2Utils::AppendMatchToSeqL( aMatchSeq, matchPart ); |
|
259 |
} |
|
260 |
} |
|
261 |
||
262 |
CleanupStack::PopAndDestroy( &matchLen ); |
|
263 |
CleanupStack::PopAndDestroy( &matchPos ); |
|
264 |
} |
|
265 |
} |
|
266 |
||
267 |
PRINT ( _L("End CPcsAlgorithm2MultiSearchHelper::SearchMatchSeqMultiL") ); |
|
268 |
} |
|
269 |
||
270 |
// ---------------------------------------------------------------------------- |
|
74
6b5524b4f673
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
63
diff
changeset
|
271 |
// CPcsAlgorithm2MultiSearchHelper::LookupMatchL |
6b5524b4f673
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
63
diff
changeset
|
272 |
// ---------------------------------------------------------------------------- |
6b5524b4f673
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
63
diff
changeset
|
273 |
void CPcsAlgorithm2MultiSearchHelper::LookupMatchL( CPsQuery& aSearchQuery, |
6b5524b4f673
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
63
diff
changeset
|
274 |
const TDesC& aData, TDes& aMatchedData ) |
6b5524b4f673
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
63
diff
changeset
|
275 |
{ |
6b5524b4f673
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
63
diff
changeset
|
276 |
_LIT( KSpace, " " ); |
6b5524b4f673
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
63
diff
changeset
|
277 |
aMatchedData.Zero(); |
6b5524b4f673
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
63
diff
changeset
|
278 |
RPointerArray<CPsQuery> queryList = MultiQueryL( aSearchQuery ); |
6b5524b4f673
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
63
diff
changeset
|
279 |
CleanupResetAndDestroyPushL( queryList ); |
6b5524b4f673
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
63
diff
changeset
|
280 |
// Convert the individual queries to string form |
6b5524b4f673
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
63
diff
changeset
|
281 |
RPointerArray<CPsQuery> mySearchQuery; |
6b5524b4f673
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
63
diff
changeset
|
282 |
CleanupResetAndDestroyPushL( mySearchQuery ); |
6b5524b4f673
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
63
diff
changeset
|
283 |
|
6b5524b4f673
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
63
diff
changeset
|
284 |
// Remember a temporary copy of query list |
6b5524b4f673
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
63
diff
changeset
|
285 |
// Copy the content of searchQuery |
6b5524b4f673
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
63
diff
changeset
|
286 |
const TInt searchQueryCount = queryList.Count(); |
6b5524b4f673
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
63
diff
changeset
|
287 |
for (TInt i = 0; i < searchQueryCount; i++ ) |
6b5524b4f673
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
63
diff
changeset
|
288 |
{ |
6b5524b4f673
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
63
diff
changeset
|
289 |
CPsQuery* tempQuery = CPsQuery::NewL(); |
6b5524b4f673
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
63
diff
changeset
|
290 |
CleanupStack::PushL( tempQuery ); |
6b5524b4f673
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
63
diff
changeset
|
291 |
iAlgorithm->FindUtilECE()->GetPartOfQueryL( *(queryList[i]), 0, |
6b5524b4f673
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
63
diff
changeset
|
292 |
queryList[i]->Count() - 1, *tempQuery ); |
6b5524b4f673
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
63
diff
changeset
|
293 |
mySearchQuery.AppendL( tempQuery ); |
6b5524b4f673
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
63
diff
changeset
|
294 |
CleanupStack::Pop( tempQuery ); // ownership transferred |
6b5524b4f673
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
63
diff
changeset
|
295 |
} |
6b5524b4f673
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
63
diff
changeset
|
296 |
|
6b5524b4f673
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
63
diff
changeset
|
297 |
// Sort the query items according to the length of each query |
6b5524b4f673
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
63
diff
changeset
|
298 |
TLinearOrder<CPsQuery> rule( CPcsAlgorithm2Utils::CompareLength ); |
6b5524b4f673
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
63
diff
changeset
|
299 |
mySearchQuery.Sort( rule ); |
6b5524b4f673
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
63
diff
changeset
|
300 |
|
6b5524b4f673
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
63
diff
changeset
|
301 |
// To hold the match results |
6b5524b4f673
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
63
diff
changeset
|
302 |
RPointerArray<TDesC> tmpMatchSet; |
6b5524b4f673
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
63
diff
changeset
|
303 |
CleanupResetAndDestroyPushL( tmpMatchSet ); |
6b5524b4f673
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
63
diff
changeset
|
304 |
|
6b5524b4f673
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
63
diff
changeset
|
305 |
TBool isMatch = ETrue; |
6b5524b4f673
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
63
diff
changeset
|
306 |
TInt wordMatches = 0; |
6b5524b4f673
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
63
diff
changeset
|
307 |
|
6b5524b4f673
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
63
diff
changeset
|
308 |
// Reset iWordMatches to zero |
6b5524b4f673
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
63
diff
changeset
|
309 |
ClearWordMatches(); |
6b5524b4f673
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
63
diff
changeset
|
310 |
|
6b5524b4f673
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
63
diff
changeset
|
311 |
// Check for each query atleast one data element matches |
6b5524b4f673
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
63
diff
changeset
|
312 |
// Loop from the last query so that longest match is seen first |
6b5524b4f673
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
63
diff
changeset
|
313 |
for (TInt queryIndex = mySearchQuery.Count() - 1; queryIndex >= 0; queryIndex-- ) |
6b5524b4f673
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
63
diff
changeset
|
314 |
{ |
6b5524b4f673
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
63
diff
changeset
|
315 |
TBool queryMatch = EFalse; |
6b5524b4f673
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
63
diff
changeset
|
316 |
CPsQuery* tmpPsQuery = mySearchQuery[queryIndex]; |
6b5524b4f673
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
63
diff
changeset
|
317 |
|
6b5524b4f673
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
63
diff
changeset
|
318 |
TInt wordIndex = -1; |
6b5524b4f673
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
63
diff
changeset
|
319 |
TLex lex( aData ); |
6b5524b4f673
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
63
diff
changeset
|
320 |
|
6b5524b4f673
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
63
diff
changeset
|
321 |
// First word |
6b5524b4f673
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
63
diff
changeset
|
322 |
TPtrC tmpData = lex.NextToken(); |
6b5524b4f673
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
63
diff
changeset
|
323 |
|
6b5524b4f673
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
63
diff
changeset
|
324 |
// Search thru multiple words |
6b5524b4f673
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
63
diff
changeset
|
325 |
while (tmpData.Length() != 0 ) |
6b5524b4f673
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
63
diff
changeset
|
326 |
{ |
6b5524b4f673
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
63
diff
changeset
|
327 |
wordIndex++; |
6b5524b4f673
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
63
diff
changeset
|
328 |
|
6b5524b4f673
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
63
diff
changeset
|
329 |
// Compare the data against query |
6b5524b4f673
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
63
diff
changeset
|
330 |
TBool matched = iAlgorithm->FindUtilECE()->MatchRefineL( tmpData, |
6b5524b4f673
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
63
diff
changeset
|
331 |
*tmpPsQuery ); |
6b5524b4f673
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
63
diff
changeset
|
332 |
|
6b5524b4f673
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
63
diff
changeset
|
333 |
if ( matched ) |
6b5524b4f673
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
63
diff
changeset
|
334 |
{ |
6b5524b4f673
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
63
diff
changeset
|
335 |
// Perform two checks. |
6b5524b4f673
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
63
diff
changeset
|
336 |
// 1. Ensure that the word is not matched against any previous query |
6b5524b4f673
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
63
diff
changeset
|
337 |
// 2. If it is the first match to the query |
6b5524b4f673
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
63
diff
changeset
|
338 |
TBool isWordMatch = IsWordMatch( 0, wordIndex ); |
6b5524b4f673
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
63
diff
changeset
|
339 |
|
6b5524b4f673
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
63
diff
changeset
|
340 |
// Check if the current word is not matched to any query |
6b5524b4f673
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
63
diff
changeset
|
341 |
// For example, there is a contact named "abc a" and query is key2 |
6b5524b4f673
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
63
diff
changeset
|
342 |
// The key2 could match the first and second 'a'. So it is required to |
6b5524b4f673
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
63
diff
changeset
|
343 |
// check if the current word has aready been matched before. |
6b5524b4f673
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
63
diff
changeset
|
344 |
|
6b5524b4f673
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
63
diff
changeset
|
345 |
if ( !isWordMatch ) |
6b5524b4f673
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
63
diff
changeset
|
346 |
{ |
6b5524b4f673
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
63
diff
changeset
|
347 |
// Check if no word is matched for this query till now |
6b5524b4f673
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
63
diff
changeset
|
348 |
if ( !queryMatch ) |
6b5524b4f673
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
63
diff
changeset
|
349 |
{ |
6b5524b4f673
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
63
diff
changeset
|
350 |
wordMatches++; |
6b5524b4f673
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
63
diff
changeset
|
351 |
queryMatch = ETrue; |
6b5524b4f673
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
63
diff
changeset
|
352 |
SetWordMap( 0, wordIndex ); |
6b5524b4f673
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
63
diff
changeset
|
353 |
// Extract matched character sequence and fill in temp array |
6b5524b4f673
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
63
diff
changeset
|
354 |
TInt len = tmpPsQuery->Count(); |
6b5524b4f673
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
63
diff
changeset
|
355 |
if ( iAlgorithm->FindUtilECE()->IsChineseWordIncluded( |
6b5524b4f673
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
63
diff
changeset
|
356 |
tmpData ) ) |
6b5524b4f673
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
63
diff
changeset
|
357 |
{ |
6b5524b4f673
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
63
diff
changeset
|
358 |
// A Chinese word could be matched by serveral keys |
6b5524b4f673
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
63
diff
changeset
|
359 |
// It is hard to know the matched query length. So set it to 1 |
6b5524b4f673
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
63
diff
changeset
|
360 |
// as a trick result |
6b5524b4f673
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
63
diff
changeset
|
361 |
len = 1; |
6b5524b4f673
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
63
diff
changeset
|
362 |
} |
6b5524b4f673
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
63
diff
changeset
|
363 |
|
6b5524b4f673
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
63
diff
changeset
|
364 |
TPtrC seq = tmpData.Left( len ); |
6b5524b4f673
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
63
diff
changeset
|
365 |
CPcsAlgorithm2Utils::AppendMatchToSeqL( tmpMatchSet, |
6b5524b4f673
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
63
diff
changeset
|
366 |
seq ); |
6b5524b4f673
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
63
diff
changeset
|
367 |
} |
6b5524b4f673
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
63
diff
changeset
|
368 |
} |
6b5524b4f673
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
63
diff
changeset
|
369 |
} |
6b5524b4f673
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
63
diff
changeset
|
370 |
|
6b5524b4f673
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
63
diff
changeset
|
371 |
// Next word |
6b5524b4f673
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
63
diff
changeset
|
372 |
tmpData.Set( lex.NextToken() ); |
6b5524b4f673
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
63
diff
changeset
|
373 |
} |
6b5524b4f673
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
63
diff
changeset
|
374 |
|
6b5524b4f673
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
63
diff
changeset
|
375 |
// No data element matches the query. Ignore this result. |
6b5524b4f673
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
63
diff
changeset
|
376 |
if ( queryMatch == EFalse ) |
6b5524b4f673
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
63
diff
changeset
|
377 |
{ |
6b5524b4f673
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
63
diff
changeset
|
378 |
isMatch = EFalse; |
6b5524b4f673
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
63
diff
changeset
|
379 |
break; |
6b5524b4f673
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
63
diff
changeset
|
380 |
} |
6b5524b4f673
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
63
diff
changeset
|
381 |
} |
6b5524b4f673
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
63
diff
changeset
|
382 |
|
6b5524b4f673
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
63
diff
changeset
|
383 |
// If match add the element to the result set |
6b5524b4f673
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
63
diff
changeset
|
384 |
// And before adding to the result set, check if there is atleast one match per query |
6b5524b4f673
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
63
diff
changeset
|
385 |
if ( isMatch && wordMatches >= mySearchQuery.Count() ) |
6b5524b4f673
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
63
diff
changeset
|
386 |
{ |
6b5524b4f673
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
63
diff
changeset
|
387 |
const TInt matchCount = tmpMatchSet.Count(); |
6b5524b4f673
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
63
diff
changeset
|
388 |
for (TInt i = 0; i < matchCount; i++ ) |
6b5524b4f673
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
63
diff
changeset
|
389 |
{ |
6b5524b4f673
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
63
diff
changeset
|
390 |
aMatchedData.Append( *tmpMatchSet[i] ); |
6b5524b4f673
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
63
diff
changeset
|
391 |
aMatchedData.Append( KSpace ); |
6b5524b4f673
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
63
diff
changeset
|
392 |
} |
6b5524b4f673
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
63
diff
changeset
|
393 |
aMatchedData.TrimRight(); |
6b5524b4f673
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
63
diff
changeset
|
394 |
} |
6b5524b4f673
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
63
diff
changeset
|
395 |
|
6b5524b4f673
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
63
diff
changeset
|
396 |
CleanupStack::PopAndDestroy( &tmpMatchSet ); // ResetAndDestroy |
6b5524b4f673
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
63
diff
changeset
|
397 |
CleanupStack::PopAndDestroy( &mySearchQuery ); // ResetAndDestroy |
6b5524b4f673
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
63
diff
changeset
|
398 |
CleanupStack::PopAndDestroy( &queryList ); // ResetAndDestroy |
6b5524b4f673
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
63
diff
changeset
|
399 |
} |
6b5524b4f673
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
63
diff
changeset
|
400 |
|
6b5524b4f673
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
63
diff
changeset
|
401 |
// ---------------------------------------------------------------------------- |
63 | 402 |
// CPcsAlgorithm2MultiSearchHelper::FilterResultsMultiL |
403 |
// Subset search function. Refer the above function for more description. |
|
404 |
// ---------------------------------------------------------------------------- |
|
405 |
void CPcsAlgorithm2MultiSearchHelper::FilterResultsMultiL(CPcsAlgorithm2FilterHelper* aAlgorithmFilterHelper, |
|
406 |
RPointerArray<CPcsPoolElement>& aSearchSet, |
|
407 |
RPointerArray<CPsQuery>& aSearchQuery, |
|
408 |
TUint8 aFilteredDataMatch, |
|
409 |
TBool aIsSearchInGroup, |
|
410 |
const RArray<TInt>& aContactsInGroup) |
|
411 |
{ |
|
412 |
PRINT ( _L("Enter CPcsAlgorithm2MultiSearchHelper::FilterResultsMultiL") ); |
|
413 |
||
414 |
//__LATENCY_MARK ( _L("CPcsAlgorithm2MultiSearchHelper::FilterResultsMultiL") ); |
|
415 |
||
416 |
TInt maxcount = 0; |
|
417 |
||
418 |
// Convert the individual queries to string form |
|
419 |
RPointerArray<CPsQuery> mySearchQuery; |
|
420 |
CleanupResetAndDestroyPushL( mySearchQuery ); |
|
421 |
||
422 |
// Remember a temporary copy of query list |
|
423 |
// Copy the content of searchQuery |
|
424 |
const TInt searchQueryCount = aSearchQuery.Count(); |
|
425 |
for (TInt i=0; i < searchQueryCount; i++) |
|
426 |
{ |
|
427 |
CPsQuery* tempQuery = CPsQuery::NewL(); |
|
428 |
CleanupStack::PushL( tempQuery ); |
|
429 |
iAlgorithm->FindUtilECE()->GetPartOfQueryL( |
|
430 |
*(aSearchQuery[i]), 0, aSearchQuery[i]->Count()-1, *tempQuery ); |
|
431 |
mySearchQuery.AppendL(tempQuery); |
|
432 |
CleanupStack::Pop(tempQuery); // ownership transferred |
|
433 |
} |
|
434 |
||
435 |
// Sort the query items according to the length of each query |
|
436 |
TLinearOrder<CPsQuery> rule(CPcsAlgorithm2Utils::CompareLength); |
|
437 |
mySearchQuery.Sort(rule); |
|
438 |
||
439 |
// To hold the match results |
|
440 |
RPointerArray<TDesC> tmpMatchSet; |
|
441 |
CleanupResetAndDestroyPushL( tmpMatchSet ); |
|
442 |
||
443 |
// Parse thru each search set elements and filter the results |
|
444 |
const TInt searchSetCount = aSearchSet.Count(); |
|
445 |
for (TInt index = 0; index < searchSetCount; index++) |
|
446 |
{ |
|
447 |
CPcsPoolElement* poolElement = static_cast<CPcsPoolElement*> (aSearchSet[index]); |
|
448 |
CPsData* psData = poolElement->GetPsData(); |
|
449 |
psData->ClearDataMatches(); |
|
450 |
||
451 |
// Skip the contact if we are doing a group search and contact doesn't belong to the group |
|
452 |
if ( aIsSearchInGroup && |
|
453 |
aContactsInGroup.Find( psData->Id() ) == KErrNotFound ) |
|
454 |
{ |
|
455 |
continue; |
|
456 |
} |
|
457 |
||
458 |
TBool isMatch = ETrue; |
|
459 |
TInt wordMatches = 0; |
|
460 |
||
461 |
// Reset iWordMatches to zero |
|
462 |
ClearWordMatches(); |
|
463 |
||
464 |
// Check for each query atleast one data element matches |
|
465 |
// Loop from the last query so that longest match is seen first |
|
466 |
for (TInt queryIndex = mySearchQuery.Count() - 1; queryIndex >= 0; queryIndex--) |
|
467 |
{ |
|
468 |
TBool queryMatch = EFalse; |
|
469 |
CPsQuery* tmpPsQuery = mySearchQuery[queryIndex]; |
|
470 |
||
471 |
const TInt dataElementCount = psData->DataElementCount(); |
|
472 |
for (TInt dataIndex = 0; dataIndex < dataElementCount; dataIndex++) |
|
473 |
{ |
|
474 |
// Filter off data fields not required in search |
|
475 |
TUint8 bitIndex = 1 << dataIndex; |
|
476 |
TUint8 filter = bitIndex & aFilteredDataMatch; |
|
477 |
||
478 |
// Omit the data fields which is not required in search |
|
479 |
// or not matched with the pool element |
|
480 |
if ( filter == 0x0 ) |
|
481 |
{ |
|
482 |
// Move to next data |
|
483 |
continue; |
|
484 |
} |
|
485 |
||
486 |
TInt wordIndex = -1; |
|
487 |
||
488 |
TLex lex(psData->Data(dataIndex)->Des()); |
|
489 |
||
490 |
// First word |
|
491 |
TPtrC tmpData = lex.NextToken(); |
|
492 |
||
493 |
// Search thru multiple words |
|
494 |
while (tmpData.Length() != 0) |
|
495 |
{ |
|
496 |
wordIndex++; |
|
497 |
||
498 |
// Compare the data against query |
|
499 |
TBool matched = iAlgorithm->FindUtilECE()->MatchRefineL(tmpData, *tmpPsQuery); |
|
500 |
||
501 |
if (matched) |
|
502 |
{ |
|
503 |
psData->SetDataMatch(dataIndex); |
|
504 |
||
505 |
// Perform two checks. |
|
506 |
// 1. Ensure that the word is not matched against any previous query |
|
507 |
// 2. If it is the first match to the query |
|
508 |
TBool isWordMatch = IsWordMatch(dataIndex, wordIndex); |
|
509 |
||
510 |
// Check if the current word is not matched to any query |
|
511 |
if (!isWordMatch) |
|
512 |
{ |
|
513 |
// Check if no word is matched for this query till now |
|
514 |
if (!queryMatch) |
|
515 |
{ |
|
516 |
wordMatches++; |
|
517 |
queryMatch = ETrue; |
|
518 |
SetWordMap(dataIndex, wordIndex); |
|
519 |
} |
|
520 |
||
521 |
// Extract matched character sequence and fill in temp array |
|
522 |
TInt len = tmpPsQuery->Count(); |
|
523 |
if (iAlgorithm->FindUtilECE()->IsChineseWordIncluded(tmpData)) |
|
524 |
{ |
|
525 |
len = 1; |
|
526 |
} |
|
527 |
||
528 |
TPtrC seq = tmpData.Left(len); |
|
529 |
CPcsAlgorithm2Utils::AppendMatchToSeqL( tmpMatchSet, seq ); |
|
530 |
||
531 |
// TODO: Match seqs could be extracted from actual |
|
532 |
// match locations by using the other overload of |
|
533 |
// CFindUtilChineseECE::MatchRefineL(). |
|
534 |
// Currently, match seq data is not used by clients. |
|
535 |
} |
|
536 |
} |
|
537 |
||
538 |
// Next word |
|
539 |
tmpData.Set(lex.NextToken()); |
|
540 |
} |
|
541 |
} |
|
542 |
||
543 |
// No data element matches the query. Ignore this result. |
|
544 |
if (queryMatch == EFalse) |
|
545 |
{ |
|
546 |
isMatch = EFalse; |
|
547 |
break; |
|
548 |
} |
|
549 |
} |
|
550 |
||
551 |
||
552 |
// If match add the element to the result set |
|
553 |
// And before adding to the result set, check if there is atleast one match per query |
|
554 |
if ( isMatch && wordMatches >= mySearchQuery.Count() ) |
|
555 |
{ |
|
556 |
aAlgorithmFilterHelper->AddL(psData, tmpMatchSet); |
|
557 |
maxcount++; |
|
558 |
} |
|
559 |
||
560 |
if ( iMaxCount != -1 && maxcount > iMaxCount ) |
|
561 |
{ |
|
562 |
break; |
|
563 |
} |
|
564 |
||
565 |
// Cleanup the match sequence array as |
|
566 |
// they are stored in pattern details structure |
|
567 |
tmpMatchSet.ResetAndDestroy(); |
|
568 |
} |
|
569 |
||
570 |
CleanupStack::PopAndDestroy( &tmpMatchSet ); // ResetAndDestroy |
|
571 |
CleanupStack::PopAndDestroy( &mySearchQuery ); // ResetAndDestroy |
|
572 |
||
573 |
//__LATENCY_MARKEND ( _L("CPcsAlgorithm2MultiSearchHelper::FilterResultsMultiL") ); |
|
574 |
||
575 |
PRINT ( _L("End CPcsAlgorithm2MultiSearchHelper::FilterResultsMultiL") ); |
|
576 |
} |
|
577 |
||
578 |
// ---------------------------------------------------------------------------- |
|
579 |
// CPcsAlgorithm2MultiSearchHelper::SetWordMap |
|
580 |
// ---------------------------------------------------------------------------- |
|
581 |
void CPcsAlgorithm2MultiSearchHelper::SetWordMap(TInt aIndex, TInt aPosition) |
|
582 |
{ |
|
583 |
TUint8 val = 1 << aPosition; |
|
584 |
iWordMatches[aIndex] |= val; |
|
585 |
} |
|
586 |
||
587 |
// ---------------------------------------------------------------------------- |
|
588 |
// CPcsAlgorithm2MultiSearchHelper::IsWordMatch |
|
589 |
// ---------------------------------------------------------------------------- |
|
590 |
TBool CPcsAlgorithm2MultiSearchHelper::IsWordMatch(TInt aDataIndex, TInt aWordIndex) |
|
591 |
{ |
|
592 |
TUint8 val = 1 << aWordIndex; |
|
593 |
return (iWordMatches[aDataIndex] & val); |
|
594 |
} |
|
595 |
||
596 |
// ---------------------------------------------------------------------------- |
|
597 |
// CPcsAlgorithm2MultiSearchHelper::BitsSet32 |
|
598 |
// Helper funtion to count the number of bits set |
|
599 |
// ---------------------------------------------------------------------------- |
|
600 |
TInt CPcsAlgorithm2MultiSearchHelper::BitsSet32(TUint32 aData) |
|
601 |
{ |
|
602 |
TInt count = 0; |
|
603 |
||
604 |
for (count = 0; aData; aData &= (aData - 1)) |
|
605 |
{ |
|
606 |
count++; |
|
607 |
} |
|
608 |
||
609 |
return count; |
|
610 |
} |
|
611 |
||
612 |
// ---------------------------------------------------------------------------- |
|
613 |
// CPcsAlgorithm2MultiSearchHelper::ClearWordMatches |
|
614 |
// Function to reset the iWordMatches |
|
615 |
// ---------------------------------------------------------------------------- |
|
616 |
void CPcsAlgorithm2MultiSearchHelper::ClearWordMatches() |
|
617 |
{ |
|
618 |
for (TInt i = 0; i < MAX_DATA_FIELDS; i++) |
|
619 |
iWordMatches[i] = 0; |
|
620 |
} |
|
621 |
||
622 |
// ---------------------------------------------------------------------------- |
|
623 |
// CPcsAlgorithm2MultiSearchHelper::MultiQuery |
|
624 |
// Checks if the query object has multiple queries embedded. |
|
625 |
// Seperator used is a space. |
|
626 |
// Scans through each query character and creates a new query object on a space. |
|
627 |
// Consequtive spaces are skipped. |
|
628 |
// Returns an array of query objects. |
|
629 |
// ---------------------------------------------------------------------------- |
|
630 |
RPointerArray<CPsQuery> CPcsAlgorithm2MultiSearchHelper::MultiQueryL(CPsQuery& aQuery) |
|
631 |
{ |
|
632 |
RPointerArray<CPsQuery> query; |
|
633 |
||
634 |
const TInt textLength = aQuery.Count(); |
|
635 |
||
636 |
for (TInt beg = 0; beg < textLength; ++beg) |
|
637 |
{ |
|
638 |
// Skip separators before next word |
|
639 |
if (!aQuery.GetItemAtL(beg).Character().IsSpace()) |
|
640 |
{ |
|
641 |
// Scan the end of the word |
|
642 |
TInt end = beg; |
|
643 |
while ( end < textLength && !aQuery.GetItemAtL(end).Character().IsSpace() ) |
|
644 |
{ |
|
645 |
end++; |
|
646 |
} |
|
647 |
||
648 |
// Create a new query object and append |
|
649 |
CPsQuery* newQuery = CPsQuery::NewL(); |
|
650 |
for (TInt i = beg; i < end; i++) |
|
651 |
{ |
|
652 |
CPsQueryItem* item = CPsQueryItem::NewL(); |
|
653 |
item->SetCharacter(aQuery.GetItemAtL(i).Character()); |
|
654 |
item->SetMode(aQuery.GetItemAtL(i).Mode()); |
|
655 |
newQuery->AppendL(*item); |
|
656 |
} |
|
657 |
query.Append(newQuery); |
|
658 |
||
659 |
// Scan for next word |
|
660 |
beg = end; |
|
661 |
} |
|
662 |
} |
|
663 |
||
664 |
return query; |
|
665 |
} |
|
666 |
||
667 |
// End of file |
|
668 |
||
669 |