31 // ---------------------------------------------------------------------------- |
32 // ---------------------------------------------------------------------------- |
32 // CPcsAlgorithm2Utils::FormCompleteSearchResultsL() |
33 // CPcsAlgorithm2Utils::FormCompleteSearchResultsL() |
33 // Merges all the respective data store result sets to single set in sorted order. |
34 // Merges all the respective data store result sets to single set in sorted order. |
34 // ---------------------------------------------------------------------------- |
35 // ---------------------------------------------------------------------------- |
35 void CPcsAlgorithm2Utils::FormCompleteSearchResultsL(RPointerArray<CPSDATA_R_PTR_ARRAY>& aSearchResultsArr, |
36 void CPcsAlgorithm2Utils::FormCompleteSearchResultsL(RPointerArray<CPSDATA_R_PTR_ARRAY>& aSearchResultsArr, |
36 RPointerArray<CPsData>& SearchResults) |
37 RPointerArray<CPsData>& aSearchResults) |
37 { |
38 { |
38 CleanupClosePushL( SearchResults ); |
|
39 |
|
40 TInt maxIndex = 0; |
39 TInt maxIndex = 0; |
41 TInt maxValue = aSearchResultsArr[maxIndex]->Count(); |
40 TInt maxValue = aSearchResultsArr[maxIndex]->Count(); |
42 TLinearOrder<CPsData> rule(CPcsAlgorithm2Utils::CompareDataBySortOrder); |
41 TLinearOrder<CPsData> rule(CPcsAlgorithm2Utils::CompareDataBySortOrder); |
43 |
42 |
44 // Find the largest array in aSearchResultsArr |
43 // Find the largest array in aSearchResultsArr |
45 for (TInt i = 1; i < aSearchResultsArr.Count(); i++) |
44 const TInt searchResultsArrCount = aSearchResultsArr.Count(); |
|
45 for (TInt i = 1; i < searchResultsArrCount; i++) |
46 { |
46 { |
47 if (aSearchResultsArr[i]->Count() > maxValue) |
47 if (aSearchResultsArr[i]->Count() > maxValue) |
48 { |
48 { |
49 maxIndex = i; |
49 maxIndex = i; |
50 maxValue = aSearchResultsArr[i]->Count(); |
50 maxValue = aSearchResultsArr[i]->Count(); |
51 } |
51 } |
52 } |
52 } |
53 |
53 |
54 // Assign the largets array to searchresults |
54 // Assign the largets array to searchresults |
55 for (TInt i = 0; i < aSearchResultsArr[maxIndex]->Count(); i++) |
55 const TInt cnt = aSearchResultsArr[maxIndex]->Count(); |
56 { |
56 for (TInt i = 0; i < cnt; i++) |
57 SearchResults.Append((*(aSearchResultsArr[maxIndex]))[i]); |
57 { |
|
58 aSearchResults.Append((*(aSearchResultsArr[maxIndex]))[i]); |
58 } |
59 } |
59 |
60 |
60 // Merge the remaining result arrays to the largest array in sequential order |
61 // Merge the remaining result arrays to the largest array in sequential order |
61 for (TInt i = 0; i < aSearchResultsArr.Count(); i++) |
62 |
|
63 for (TInt i = 0; i < searchResultsArrCount; i++) |
62 { |
64 { |
63 // Check if we are not copying again the largest array |
65 // Check if we are not copying again the largest array |
64 if ((i != maxIndex) && ((aSearchResultsArr[i])->Count() != 0)) |
66 if ((i != maxIndex) && ((aSearchResultsArr[i])->Count() != 0)) |
65 { |
67 { |
66 TInt numElements = (aSearchResultsArr[i])->Count(); |
68 TInt numElements = (aSearchResultsArr[i])->Count(); |
67 for (TInt j = 0; j < numElements; j++) |
69 for (TInt j = 0; j < numElements; j++) |
68 { |
70 { |
69 SearchResults.InsertInOrderAllowRepeatsL((*(aSearchResultsArr[i]))[j], rule); |
71 aSearchResults.InsertInOrderAllowRepeatsL((*(aSearchResultsArr[i]))[j], rule); |
70 } |
72 } |
71 } |
73 } |
72 } |
74 } |
73 CleanupStack::Pop(); |
|
74 } |
75 } |
75 |
76 |
76 // ---------------------------------------------------------------------------- |
77 // ---------------------------------------------------------------------------- |
77 // CPcsAlgorithm2Utils::MyCompareC() |
78 // CPcsAlgorithm2Utils::MyCompareC() |
78 // Lang specific MyCompareC |
79 // Lang specific MyCompareC |
119 |
120 |
120 // Get the index order based on sort order from the cache |
121 // Get the index order based on sort order from the cache |
121 cache->GetIndexOrder(indexOrder); |
122 cache->GetIndexOrder(indexOrder); |
122 |
123 |
123 // Append sort order elements first |
124 // Append sort order elements first |
124 for (int i = 0; i < indexOrder.Count(); i++) |
125 const TInt indexOrderCount1 = indexOrder.Count(); |
|
126 for (int i = 0; i < indexOrderCount1; i++) |
125 { |
127 { |
126 TInt index = indexOrder[i]; |
128 TInt index = indexOrder[i]; |
127 if (index < aObject1.DataElementCount() && aObject1.Data(index)) |
129 if (index < aObject1.DataElementCount() && aObject1.Data(index)) |
128 { |
130 { |
129 // Trim the unnecessary white spaces/special chars before we compare |
131 // Trim the unnecessary white spaces/special chars before we compare |
156 |
158 |
157 indexOrder.Reset(); |
159 indexOrder.Reset(); |
158 |
160 |
159 // Get the index order based on sort order from the cache |
161 // Get the index order based on sort order from the cache |
160 cache->GetIndexOrder(indexOrder); |
162 cache->GetIndexOrder(indexOrder); |
|
163 const TInt indexOrderCount2 = indexOrder.Count(); |
161 |
164 |
162 // Append sort order elements first |
165 // Append sort order elements first |
163 for (int i = 0; i < indexOrder.Count(); i++) |
166 for (int i = 0; i < indexOrderCount2; i++) |
164 { |
167 { |
165 TInt index = indexOrder[i]; |
168 TInt index = indexOrder[i]; |
166 if (index < aObject2.DataElementCount() && aObject2.Data(index)) |
169 if (index < aObject2.DataElementCount() && aObject2.Data(index)) |
167 { |
170 { |
168 // Trim the unnecessary white spaces/special chars before we compare |
171 // Trim the unnecessary white spaces/special chars before we compare |
193 data2.TrimAll(); |
196 data2.TrimAll(); |
194 return (CPcsAlgorithm2Utils::MyCompareC(data1, data2)); |
197 return (CPcsAlgorithm2Utils::MyCompareC(data1, data2)); |
195 } |
198 } |
196 |
199 |
197 // ---------------------------------------------------------------------------- |
200 // ---------------------------------------------------------------------------- |
|
201 // CPcsAlgorithm2Utils::CompareExact() |
|
202 // |
|
203 // ---------------------------------------------------------------------------- |
|
204 TBool CPcsAlgorithm2Utils::CompareExact(const TDesC& aFirst, const TDesC& aSecond) |
|
205 { |
|
206 return aFirst == aSecond; |
|
207 } |
|
208 |
|
209 // ---------------------------------------------------------------------------- |
|
210 // CPcsAlgorithm2Utils::CompareLength() |
|
211 // |
|
212 // ---------------------------------------------------------------------------- |
|
213 TInt CPcsAlgorithm2Utils::CompareLength(const CPsQuery& aFirst, const CPsQuery& aSecond) |
|
214 { |
|
215 CPsQuery& first = const_cast<CPsQuery&> (aFirst); |
|
216 CPsQuery& second = const_cast<CPsQuery&> (aSecond); |
|
217 |
|
218 return (first.Count() - second.Count()); |
|
219 } |
|
220 |
|
221 // ---------------------------------------------------------------------------- |
198 // CPcsAlgorithm2Utils::MyTrim() |
222 // CPcsAlgorithm2Utils::MyTrim() |
199 // Trim off all white spaces and special characters |
223 // Trim off all white spaces and special characters |
200 // This behavior is required to mimic the current phonebook sort sequence |
224 // This behavior is required to mimic the current phonebook sort sequence |
201 // ---------------------------------------------------------------------------- |
225 // ---------------------------------------------------------------------------- |
202 void CPcsAlgorithm2Utils::MyTrim(TDes& aString) |
226 void CPcsAlgorithm2Utils::MyTrim(TDes& aString) |
231 } |
255 } |
232 |
256 |
233 return ETrue; |
257 return ETrue; |
234 } |
258 } |
235 |
259 |
|
260 // ---------------------------------------------------------------------------- |
|
261 // CPcsAlgorithm1Helper::FilterDataFieldsL() |
|
262 // Constructs a bit pattern using the required/supported data fields |
|
263 // For example, 6, 4 and 27 are supported fields <-- 00000111 |
|
264 // 6 and 4 are required fields <-- 00000011 |
|
265 // Bit pattern returned is 00000011. |
|
266 // ---------------------------------------------------------------------------- |
|
267 TUint8 CPcsAlgorithm2Utils::FilterDataFieldsL(const RArray<TInt>& aRequiredDataFields, |
|
268 const RArray<TInt>& aSupportedDataFields) |
|
269 { |
|
270 TUint8 filteredMatch = 0x0; |
|
271 const TInt supportedDataFieldsCount = aSupportedDataFields.Count(); |
|
272 const TInt requiredDataFieldsCount = aRequiredDataFields.Count(); |
|
273 for ( TInt i = 0; i < supportedDataFieldsCount; i++ ) |
|
274 { |
|
275 for ( TInt j = 0; j < requiredDataFieldsCount; j++ ) |
|
276 { |
|
277 if ( aSupportedDataFields[i] == aRequiredDataFields[j] ) |
|
278 { |
|
279 TUint8 val = 1 << i; |
|
280 filteredMatch |= val; |
|
281 } |
|
282 } |
|
283 } |
|
284 |
|
285 return filteredMatch; |
|
286 } |
|
287 |
|
288 // ---------------------------------------------------------------------------- |
|
289 // CPcsAlgorithm2Utils::AppendMatchToSeqL |
|
290 // ---------------------------------------------------------------------------- |
|
291 void CPcsAlgorithm2Utils::AppendMatchToSeqL( |
|
292 RPointerArray<TDesC>& aMatchSeq, const TDesC& aMatch ) |
|
293 { |
|
294 HBufC* seq = aMatch.AllocLC(); |
|
295 seq->Des().UpperCase(); |
|
296 TIdentityRelation<TDesC> rule(CompareExact); |
|
297 if ( aMatchSeq.Find(seq, rule) == KErrNotFound ) |
|
298 { |
|
299 aMatchSeq.AppendL(seq); |
|
300 CleanupStack::Pop( seq ); |
|
301 } |
|
302 else |
|
303 { |
|
304 CleanupStack::PopAndDestroy( seq ); |
|
305 } |
|
306 } |
|
307 |
|
308 // ---------------------------------------------------------------------------- |
|
309 // CPcsAlgorithm2Utils::MatchesOverlap |
|
310 // Check if two match location items have overlapping indices. |
|
311 // ---------------------------------------------------------------------------- |
|
312 TBool CPcsAlgorithm2Utils::MatchesOverlap( const TPsMatchLocation& aFirst, |
|
313 const TPsMatchLocation& aSecond ) |
|
314 { |
|
315 TBool overlap = EFalse; |
|
316 |
|
317 if ( aFirst.index == aSecond.index ) |
|
318 { |
|
319 overlap = ETrue; |
|
320 } |
|
321 else |
|
322 { |
|
323 // give arguments alias names where first begins before the second |
|
324 TInt firstPos( aFirst.index ); |
|
325 TInt firstLen( aFirst.length ); |
|
326 TInt secondPos( aSecond.index ); |
|
327 if ( firstPos > secondPos ) |
|
328 { |
|
329 firstPos = aSecond.index; |
|
330 firstLen = aSecond.length; |
|
331 secondPos = aFirst.index; |
|
332 } |
|
333 |
|
334 // there is an overlap if the end of the first comes after |
|
335 // beginning of the second |
|
336 if ( firstPos + firstLen > secondPos ) |
|
337 { |
|
338 overlap = ETrue; |
|
339 } |
|
340 } |
|
341 |
|
342 return overlap; |
|
343 } |
|
344 |
236 // End of File |
345 // End of File |
237 |
346 |