94 // data element has not matched for multiple queries. |
104 // data element has not matched for multiple queries. |
95 // (9) Now include the element in the result. |
105 // (9) Now include the element in the result. |
96 // ---------------------------------------------------------------------------- |
106 // ---------------------------------------------------------------------------- |
97 void CPcsAlgorithm1MultiSearchHelper::SearchMultiL(const CPsSettings& aSettings, |
107 void CPcsAlgorithm1MultiSearchHelper::SearchMultiL(const CPsSettings& aSettings, |
98 RPointerArray<CPsQuery>& aPsQuery, |
108 RPointerArray<CPsQuery>& aPsQuery, |
99 TBool isSearchInGroup, |
109 TBool aIsSearchInGroup, |
100 RArray<TInt>& aContactsInGroup, |
110 RArray<TInt>& aContactsInGroup, |
101 RPointerArray<CPsData>& searchResults, |
111 RPointerArray<CPsData>& aSearchResults, |
102 RPointerArray<CPsPattern>& searchSeqs ) |
112 RPointerArray<CPsPattern>& aSearchSeqs ) |
103 { |
113 { |
104 PRINT ( _L("Enter CPcsAlgorithm1MultiSearchHelper::SearchMultiL") ); |
114 PRINT ( _L("Enter CPcsAlgorithm1MultiSearchHelper::SearchMultiL") ); |
105 |
115 |
106 __LATENCY_MARK ( _L("CPcsAlgorithm1MultiSearchHelper::SearchMultiL") ); |
116 __LATENCY_MARK ( _L("CPcsAlgorithm1MultiSearchHelper::SearchMultiL") ); |
107 |
117 |
108 PRINTQUERYLIST ( _L("CPcsAlgorithm1MultiSearchHelper::SearchMultiL: "), aPsQuery ); |
118 PRINTQUERYLIST ( _L("CPcsAlgorithm1MultiSearchHelper::SearchMultiL: "), aPsQuery ); |
109 |
119 |
110 // Create CPcsAlgorithm1FilterHelper object to be used for filtering the results |
120 // Create CPcsAlgorithm1FilterHelper object to be used for filtering the results |
111 TSortType sortType = aSettings.GetSortType(); |
121 TSortType sortType = aSettings.GetSortType(); |
112 CPcsAlgorithm1FilterHelper* filterHelper = CPcsAlgorithm1FilterHelper::NewL(sortType); |
122 CPcsAlgorithm1FilterHelper* filterHelper = CPcsAlgorithm1FilterHelper::NewL(sortType); |
|
123 CleanupStack::PushL( filterHelper ); |
113 RPointerArray<CPcsPoolElement> elements; |
124 RPointerArray<CPcsPoolElement> elements; |
114 |
125 CleanupClosePushL( elements ); |
115 iMultiSearchResultsArr.ResetAndDestroy(); |
126 |
|
127 iMultiSearchResultsArr.ResetAndDestroy(); |
116 |
128 |
117 // Get the data stores |
129 // Get the data stores |
118 RPointerArray<TDesC> aDataStores; |
130 RPointerArray<TDesC> dataStores; |
119 aSettings.SearchUrisL(aDataStores); |
131 CleanupResetAndDestroyPushL( dataStores ); |
|
132 aSettings.SearchUrisL(dataStores); |
120 |
133 |
121 // Get the required display fields from the client |
134 // Get the required display fields from the client |
122 RArray<TInt> requiredDataFields; |
135 RArray<TInt> requiredDataFields; |
|
136 CleanupClosePushL( requiredDataFields ); |
123 aSettings.DisplayFieldsL(requiredDataFields); |
137 aSettings.DisplayFieldsL(requiredDataFields); |
124 |
138 |
125 // Search based on first character of 1st item in query list |
139 // Search from cache based on first character of 1st item in query list |
126 TInt numValue = iKeyMap->PoolIdForCharacter(aPsQuery[0]->GetItemAtL(0).Character()); |
140 const CPsQueryItem& firstCharItem = aPsQuery[0]->GetItemAtL(0); |
|
141 TInt cachePoolId = iKeyMap->PoolIdForCharacter( firstCharItem.Character(), firstCharItem.Mode() ); |
127 |
142 |
128 // Get the elements from all the databases |
143 // Get the elements from all the databases |
129 for ( int dsIndex = 0; |
144 for ( TInt dsIndex = 0; |
130 dsIndex < aDataStores.Count(); |
145 dsIndex < dataStores.Count(); |
131 dsIndex++ ) |
146 dsIndex++ ) |
132 { |
147 { |
133 RPointerArray<CPsData> *temp = new (ELeave) RPointerArray<CPsData> (); |
148 RPointerArray<CPsData> *temp = new (ELeave) RPointerArray<CPsData> (); |
134 iMultiSearchResultsArr.Append(temp); |
149 iMultiSearchResultsArr.Append(temp); |
135 |
150 |
136 // Get the contents for this data store |
151 // Get the contents for this data store |
137 TInt arrayIndex = iAlgorithm->GetCacheIndex(*(aDataStores[dsIndex])); |
152 TInt arrayIndex = iAlgorithm->GetCacheIndex(*(dataStores[dsIndex])); |
138 if ( arrayIndex < 0 ) continue; |
153 if ( arrayIndex < 0 ) continue; |
139 CPcsCache* cache = iAlgorithm->GetCache(arrayIndex); |
154 CPcsCache* cache = iAlgorithm->GetCache(arrayIndex); |
140 cache->GetContactsForKeyL(numValue,elements); |
155 cache->GetContactsForKeyL(cachePoolId, elements); |
141 |
156 |
142 // Get the supported data fields for this data store |
157 // Get the supported data fields for this data store |
143 RArray<TInt> supportedDataFields; |
158 RArray<TInt> supportedDataFields; |
|
159 CleanupClosePushL( supportedDataFields ); |
144 cache->GetDataFields(supportedDataFields); |
160 cache->GetDataFields(supportedDataFields); |
145 |
161 |
146 // Get the filtered data fields for this data store |
162 // Get the filtered data fields for this data store |
147 TUint8 filteredDataMatch = FilterDataFieldsL(requiredDataFields, |
163 TUint8 filteredDataMatch = FilterDataFieldsL(requiredDataFields, |
148 supportedDataFields); |
164 supportedDataFields); |
149 |
165 |
150 // Filter the results now |
166 // Filter the results now |
151 FilterResultsMultiL(filterHelper, |
167 FilterResultsMultiL(filterHelper, |
152 elements, |
168 elements, |
153 aPsQuery, |
169 aPsQuery, |
154 filteredDataMatch, |
170 filteredDataMatch, |
155 isSearchInGroup, |
171 aIsSearchInGroup, |
156 aContactsInGroup); |
172 aContactsInGroup); |
157 |
173 |
158 // If alphabetical sorting, get the results for this datastore |
174 // If alphabetical sorting, get the results for this datastore |
159 if ( sortType == EAlphabetical ) |
175 if ( sortType == EAlphabetical ) |
160 { |
176 { |
161 filterHelper->GetResults(*(iMultiSearchResultsArr[dsIndex])); |
177 filterHelper->GetResults(*(iMultiSearchResultsArr[dsIndex])); |
162 } |
178 } |
163 |
179 |
164 elements.Reset(); |
180 elements.Reset(); |
165 supportedDataFields.Reset(); |
181 CleanupStack::PopAndDestroy( &supportedDataFields ); // Close |
166 } |
182 } |
167 aDataStores.ResetAndDestroy(); |
183 CleanupStack::PopAndDestroy( &requiredDataFields ); // Close |
168 requiredDataFields.Reset(); |
184 CleanupStack::PopAndDestroy( &dataStores ); // ResetAndDestroy |
169 |
185 |
170 // If alphabetical sorting, merge the result sets of all datastores |
186 // If alphabetical sorting, merge the result sets of all datastores |
171 if ( sortType == EAlphabetical ) |
187 if ( sortType == EAlphabetical ) |
172 { |
188 { |
173 // Form the complete searchResults array |
189 // Form the complete searchResults array |
174 CPcsAlgorithm1Utils::FormCompleteSearchResultsL(iMultiSearchResultsArr, |
190 CPcsAlgorithm1Utils::FormCompleteSearchResultsL(iMultiSearchResultsArr, |
175 searchResults); |
191 aSearchResults); |
176 } |
192 } |
177 else |
193 else |
178 { |
194 { |
179 // Results are already sorted patternbased |
195 // Results are already sorted patternbased |
180 filterHelper->GetResults(searchResults); |
196 filterHelper->GetResults(aSearchResults); |
181 } |
197 } |
182 |
198 |
183 // Get the sorted match sequence list |
199 // Get the sorted match sequence list |
184 filterHelper->GetPatternsL(searchSeqs); |
200 filterHelper->GetPatternsL(aSearchSeqs); |
185 |
201 |
186 PRINT1 ( _L("CPcsAlgorithm1MultiSearchHelper::SearchMultiL: Number of search results = %d"), searchResults.Count() ); |
202 PRINT1 ( _L("CPcsAlgorithm1MultiSearchHelper::SearchMultiL: Number of search results = %d"), aSearchResults.Count() ); |
187 |
203 |
188 // Cleanup |
204 // Cleanup |
189 for(TInt i = 0; i < iMultiSearchResultsArr.Count(); i++) |
205 for(TInt i = 0; i < iMultiSearchResultsArr.Count(); i++) |
190 { |
206 { |
191 iMultiSearchResultsArr[i]->Reset(); |
207 iMultiSearchResultsArr[i]->Reset(); |
192 delete iMultiSearchResultsArr[i]; |
208 delete iMultiSearchResultsArr[i]; |
193 iMultiSearchResultsArr[i] = NULL; |
209 iMultiSearchResultsArr[i] = NULL; |
194 } |
210 } |
195 |
211 |
196 iMultiSearchResultsArr.Reset(); |
212 iMultiSearchResultsArr.Reset(); |
197 delete filterHelper; |
213 CleanupStack::PopAndDestroy( &elements ); // Close |
|
214 CleanupStack::PopAndDestroy( filterHelper ); |
198 |
215 |
199 __LATENCY_MARKEND ( _L("CPcsAlgorithm1MultiSearchHelper::SearchMultiL") ); |
216 __LATENCY_MARKEND ( _L("CPcsAlgorithm1MultiSearchHelper::SearchMultiL") ); |
200 |
217 |
201 PRINT ( _L("End CPcsAlgorithm1MultiSearchHelper::SearchMultiL") ); |
218 PRINT ( _L("End CPcsAlgorithm1MultiSearchHelper::SearchMultiL") ); |
202 } |
219 } |
430 // CPcsAlgorithm1MultiSearchHelper::FilterResultsMultiL |
445 // CPcsAlgorithm1MultiSearchHelper::FilterResultsMultiL |
431 // Subset search function. Refer the above function for more description. |
446 // Subset search function. Refer the above function for more description. |
432 // ---------------------------------------------------------------------------- |
447 // ---------------------------------------------------------------------------- |
433 void CPcsAlgorithm1MultiSearchHelper::FilterResultsMultiL( |
448 void CPcsAlgorithm1MultiSearchHelper::FilterResultsMultiL( |
434 CPcsAlgorithm1FilterHelper* aAlgorithmFilterHelper, |
449 CPcsAlgorithm1FilterHelper* aAlgorithmFilterHelper, |
435 RPointerArray<CPcsPoolElement>& searchSet, |
450 RPointerArray<CPcsPoolElement>& aSearchSet, |
436 RPointerArray<CPsQuery>& searchQuery, |
451 RPointerArray<CPsQuery>& aSearchQuery, |
437 TUint8 aFilteredDataMatch, |
452 TUint8 aFilteredDataMatch, |
438 TBool isSearchInGroup, |
453 TBool aIsSearchInGroup, |
439 RArray<TInt>& aContactsInGroup) |
454 RArray<TInt>& aContactsInGroup) |
440 { |
455 { |
441 PRINT ( _L("Enter CPcsAlgorithm1MultiSearchHelper::FilterResultsMultiL") ); |
456 PRINT ( _L("Enter CPcsAlgorithm1MultiSearchHelper::FilterResultsMultiL") ); |
442 |
457 |
443 __LATENCY_MARK ( _L("CPcsAlgorithm1MultiSearchHelper::FilterResultsMultiL") ); |
458 __LATENCY_MARK ( _L("CPcsAlgorithm1MultiSearchHelper::FilterResultsMultiL") ); |
444 |
459 |
445 // Convert the individual queries to string form |
460 // Convert the individual queries to string form |
446 RPointerArray<HBufC> queryList; |
461 RPointerArray<HBufC> queryList; |
447 RPointerArray<HBufC> tempqueryList; |
462 CleanupResetAndDestroyPushL( queryList ); |
448 ConvertQueryToListL(searchQuery, queryList); |
463 RPointerArray<HBufC> tempqueryList; |
|
464 CleanupClosePushL( tempqueryList ); |
|
465 ConvertQueryToListL(aSearchQuery, queryList); |
449 |
466 |
450 // Remember a temporary copy of query list |
467 // Remember a temporary copy of query list |
451 // since we sort the queries |
468 // since we sort the queries |
452 for( TInt i = 0; i < queryList.Count(); i++) |
469 for( TInt i = 0; i < queryList.Count(); i++) |
453 { |
470 { |
481 TBool queryMatch = EFalse; |
499 TBool queryMatch = EFalse; |
482 HBufC* tmpQuery = queryList[queryIndex]; |
500 HBufC* tmpQuery = queryList[queryIndex]; |
483 // Get the original query mode corresponding to this query |
501 // Get the original query mode corresponding to this query |
484 TInt modeIndex = tempqueryList.Find(tmpQuery); |
502 TInt modeIndex = tempqueryList.Find(tmpQuery); |
485 |
503 |
486 for ( TInt dataIndex = 0; dataIndex < psData->DataElementCount(); dataIndex++ ) |
504 TInt dataCount = psData->DataElementCount(); |
|
505 __ASSERT_DEBUG( dataCount < MAX_DATA_FIELDS, Panic(KErrOverflow) ); |
|
506 |
|
507 for ( TInt dataIndex = 0; dataIndex < dataCount; dataIndex++ ) |
487 { |
508 { |
488 // Filter off data fields not required in search |
509 // Filter off data fields not required in search |
489 TReal bitIndex; |
510 TUint8 bitIndex = 1 << dataIndex; |
490 Math::Pow(bitIndex, 2, dataIndex); |
511 |
491 |
512 TUint8 filter = bitIndex & aFilteredDataMatch; |
492 TUint8 filter = (TUint8)bitIndex & aFilteredDataMatch; |
|
493 if ( filter == 0x0 ) |
513 if ( filter == 0x0 ) |
494 { |
514 { |
495 // Move to next data |
515 // Move to next data |
496 continue; |
516 continue; |
497 } |
517 } |
498 |
518 |
499 TInt wordIndex = -1; |
519 TInt wordIndex = -1; |
500 |
520 |
501 TLex lex(psData->Data(dataIndex)->Des()); |
521 TLex lex(psData->Data(dataIndex)->Des()); |
502 |
522 |
503 // First word |
523 // First word |
504 TPtrC tmpData = lex.NextToken(); |
524 TPtrC tmpData = lex.NextToken(); |
505 |
525 |
506 // Search thru multiple words |
526 // Search thru multiple words |
507 while ( tmpData.Length() != 0 ) |
527 while ( tmpData.Length() != 0 ) |
508 { |
528 { |
509 wordIndex++; |
529 wordIndex++; |
510 |
530 |
511 TBuf<KPsQueryMaxLen> data; |
531 TBuf<KPsQueryMaxLen> data; |
512 |
532 |
513 // Convert the data to required form (mode specific) |
533 // Convert the data to required form (mode specific) |
514 iKeyMap->GetMixedKeyStringForDataL(*searchQuery[modeIndex], tmpData, data); |
534 iKeyMap->GetMixedKeyStringForDataL(*aSearchQuery[modeIndex], tmpData, data); |
515 |
535 |
516 // Compare the data against query |
536 // Compare the data against query |
517 if ( CPcsAlgorithm1Utils::MyCompareKeyAndString(data, *tmpQuery, *searchQuery[modeIndex]) ) |
537 if ( CPcsAlgorithm1Utils::MyCompareKeyAndString(data, *tmpQuery, *aSearchQuery[modeIndex]) ) |
518 { |
538 { |
519 psData->SetDataMatch(dataIndex); |
539 psData->SetDataMatch(dataIndex); |
520 |
540 |
521 // Perform two checks. |
541 // Perform two checks. |
522 // 1. Ensure that the word is not matched against any previous query |
542 // 1. Ensure that the word is not matched against any previous query |
523 // 2. If it is the first match to the query |
543 // 2. If it is the first match to the query |
524 TBool isWordMatch = IsWordMatch(dataIndex, wordIndex); |
544 TBool isWordMatch = IsWordMatch(dataIndex, wordIndex); |
525 |
545 |
526 // Check if the current word is not matched to any query |
546 // Check if the current word is not matched to any query |
527 if( !isWordMatch ) |
547 if( !isWordMatch ) |
528 { |
548 { |
529 // Check if no word is matched for this query till now |
549 // Check if no word is matched for this query till now |
583 } |
603 } |
584 } |
604 } |
585 |
605 |
586 // Cleanup the match sequence array as |
606 // Cleanup the match sequence array as |
587 // they are stored in pattern details structure |
607 // they are stored in pattern details structure |
588 tmpMatchSet.ResetAndDestroy(); |
608 tmpMatchSet.ResetAndDestroy(); |
589 } |
609 } |
590 |
610 |
591 // Free the query list |
611 // Free the query list |
592 queryList.ResetAndDestroy(); |
612 CleanupStack::PopAndDestroy( &tmpMatchSet ); // ResetAndDestroy |
593 tempqueryList.Reset(); |
613 CleanupStack::PopAndDestroy( &tempqueryList ); // Close |
|
614 CleanupStack::PopAndDestroy( &queryList ); // ResetAndDestroy |
594 |
615 |
595 __LATENCY_MARKEND ( _L("CPcsAlgorithm1MultiSearchHelper::FilterResultsMultiL") ); |
616 __LATENCY_MARKEND ( _L("CPcsAlgorithm1MultiSearchHelper::FilterResultsMultiL") ); |
596 |
617 |
597 PRINT ( _L("End CPcsAlgorithm1MultiSearchHelper::FilterResultsMultiL") ); |
618 PRINT ( _L("End CPcsAlgorithm1MultiSearchHelper::FilterResultsMultiL") ); |
598 } |
619 } |
599 |
620 |
600 // ---------------------------------------------------------------------------- |
621 // ---------------------------------------------------------------------------- |
601 // CPcsAlgorithm1MultiSearchHelper::SetWordMap() |
622 // CPcsAlgorithm1MultiSearchHelper::SetWordMap() |
602 // ---------------------------------------------------------------------------- |
623 // ---------------------------------------------------------------------------- |
603 void CPcsAlgorithm1MultiSearchHelper::SetWordMap( TInt aIndex, TInt aPosition) |
624 void CPcsAlgorithm1MultiSearchHelper::SetWordMap(TInt aIndex, TInt aPosition) |
604 { |
625 { |
605 TReal val; |
626 TUint8 val = 1 << aPosition; |
606 Math::Pow(val, 2, aPosition); |
627 iWordMatches[aIndex] |= val; |
607 |
|
608 iWordMatches[aIndex] |= (TUint8)val; |
|
609 } |
628 } |
610 |
629 |
611 // ---------------------------------------------------------------------------- |
630 // ---------------------------------------------------------------------------- |
612 // CPcsAlgorithm1MultiSearchHelper::IsWordMatch() |
631 // CPcsAlgorithm1MultiSearchHelper::IsWordMatch() |
613 // ---------------------------------------------------------------------------- |
632 // ---------------------------------------------------------------------------- |
614 TBool CPcsAlgorithm1MultiSearchHelper::IsWordMatch(TInt aDataIndex, TInt aWordIndex) |
633 TBool CPcsAlgorithm1MultiSearchHelper::IsWordMatch(TInt aDataIndex, TInt aWordIndex) |
615 { |
634 { |
616 TReal val; |
635 TUint8 val = 1 << aWordIndex; |
617 Math::Pow(val, 2, aWordIndex); |
636 return (iWordMatches[aDataIndex] & val); |
618 |
|
619 return(iWordMatches[aDataIndex] & (TUint8)val); |
|
620 } |
637 } |
621 |
638 |
622 // ---------------------------------------------------------------------------- |
639 // ---------------------------------------------------------------------------- |
623 // CPcsAlgorithm1MultiSearchHelper::ClearWordMatches |
640 // CPcsAlgorithm1MultiSearchHelper::ClearWordMatches |
624 // Function to reset the iWordMatches |
641 // Function to reset the iWordMatches |