88 |
88 |
89 // ---------------------------------------------------------------------------- |
89 // ---------------------------------------------------------------------------- |
90 // CPcsAlgorithm1Helper::SearchSingleL |
90 // CPcsAlgorithm1Helper::SearchSingleL |
91 // Search function for query in ITU-T mode, QWERTY mode, or Mixed (ITU-T and QWERTY) mode. |
91 // Search function for query in ITU-T mode, QWERTY mode, or Mixed (ITU-T and QWERTY) mode. |
92 // ---------------------------------------------------------------------------- |
92 // ---------------------------------------------------------------------------- |
93 void CPcsAlgorithm1Helper::SearchSingleL(const CPsSettings& aSettings, |
93 void CPcsAlgorithm1Helper::SearchSingleL( const CPsSettings& aSettings, |
94 CPsQuery& aPsQuery, |
94 CPsQuery& aPsQuery, |
95 TBool isSearchInGroup, |
95 TBool aIsSearchInGroup, |
96 RArray<TInt>& aContactsInGroup, |
96 RArray<TInt>& aContactsInGroup, |
97 RPointerArray<CPsData>& searchResults, |
97 RPointerArray<CPsData>& aSearchResults, |
98 RPointerArray<CPsPattern>& searchSeqs ) |
98 RPointerArray<CPsPattern>& aSearchSeqs ) |
99 { |
99 { |
100 PRINT ( _L("Enter CPcsAlgorithm1Helper::SearchSingleL") ); |
100 PRINT ( _L("Enter CPcsAlgorithm1Helper::SearchSingleL") ); |
101 |
101 |
102 __LATENCY_MARK ( _L("CPcsAlgorithm1Helper::SearchSingleL") ); |
102 __LATENCY_MARK ( _L("CPcsAlgorithm1Helper::SearchSingleL") ); |
103 |
103 |
104 // Create filtering helper for the required sort type |
104 // Create filtering helper for the required sort type |
105 TSortType sortType = aSettings.GetSortType(); |
105 TSortType sortType = aSettings.GetSortType(); |
106 CPcsAlgorithm1FilterHelper* filterHelper = CPcsAlgorithm1FilterHelper::NewL(sortType); |
106 CPcsAlgorithm1FilterHelper* filterHelper = CPcsAlgorithm1FilterHelper::NewL(sortType); |
107 |
107 CleanupStack::PushL( filterHelper ); |
108 // Search based on first character |
108 |
109 TInt numValue = iKeyMap->PoolIdForCharacter(aPsQuery.GetItemAtL(0).Character()); |
109 // Search from cache based on first character |
|
110 const CPsQueryItem& firstCharItem = aPsQuery.GetItemAtL(0); |
|
111 TInt cachePoolId = iKeyMap->PoolIdForCharacter( firstCharItem.Character(), firstCharItem.Mode() ); |
110 |
112 |
111 // Reset the result set array for new search |
113 // Reset the result set array for new search |
112 iSearchResultsArr.ResetAndDestroy(); |
114 iSearchResultsArr.ResetAndDestroy(); |
113 |
115 |
114 // Get the data stores |
116 // Get the data stores |
115 RPointerArray<TDesC> aDataStores; |
117 RPointerArray<TDesC> dataStores; |
116 aSettings.SearchUrisL(aDataStores); |
118 CleanupResetAndDestroyPushL( dataStores ); |
|
119 aSettings.SearchUrisL(dataStores); |
117 |
120 |
118 // Get the required display fields from the client |
121 // Get the required display fields from the client |
119 RArray<TInt> requiredDataFields; |
122 RArray<TInt> requiredDataFields; |
|
123 CleanupClosePushL( requiredDataFields ); |
120 aSettings.DisplayFieldsL(requiredDataFields); |
124 aSettings.DisplayFieldsL(requiredDataFields); |
121 |
125 |
122 // Perform search for each required data store |
126 // Perform search for each required data store |
123 RPointerArray<CPcsPoolElement> elements; |
127 RPointerArray<CPcsPoolElement> elements; |
124 |
128 CleanupClosePushL( elements ); |
125 for ( int dsIndex = 0; |
129 |
126 dsIndex < aDataStores.Count(); |
130 for ( TInt dsIndex = 0; |
|
131 dsIndex < dataStores.Count(); |
127 dsIndex++ ) |
132 dsIndex++ ) |
128 { |
133 { |
129 RPointerArray<CPsData> *temp = new (ELeave) RPointerArray<CPsData> (); |
134 RPointerArray<CPsData> *temp = new (ELeave) RPointerArray<CPsData> (); |
130 iSearchResultsArr.Append(temp); |
135 iSearchResultsArr.Append(temp); |
131 |
136 |
132 // Get the contents for this data store |
137 // Get the contents for this data store |
133 TInt arrayIndex = iAlgorithm->GetCacheIndex(*(aDataStores[dsIndex])); |
138 TInt arrayIndex = iAlgorithm->GetCacheIndex(*(dataStores[dsIndex])); |
134 if ( arrayIndex < 0 ) continue; |
139 if ( arrayIndex < 0 ) continue; |
135 CPcsCache* cache = iAlgorithm->GetCache(arrayIndex); |
140 CPcsCache* cache = iAlgorithm->GetCache(arrayIndex); |
136 cache->GetContactsForKeyL(numValue,elements); |
141 cache->GetContactsForKeyL(cachePoolId, elements); |
137 |
142 |
138 // Get the supported data fields for this data store |
143 // Get the supported data fields for this data store |
139 RArray<TInt> supportedDataFields; |
144 RArray<TInt> supportedDataFields; |
|
145 CleanupClosePushL( supportedDataFields ); |
140 cache->GetDataFields(supportedDataFields); |
146 cache->GetDataFields(supportedDataFields); |
141 |
147 |
142 // Get the filtered data fields for this data store |
148 // Get the filtered data fields for this data store |
143 TUint8 filteredDataMatch = FilterDataFieldsL(requiredDataFields, |
149 TUint8 filteredDataMatch = FilterDataFieldsL(requiredDataFields, |
144 supportedDataFields); |
150 supportedDataFields); |
146 // Perform filtering |
152 // Perform filtering |
147 FilterResultsSingleL(filterHelper, |
153 FilterResultsSingleL(filterHelper, |
148 elements, |
154 elements, |
149 aPsQuery, |
155 aPsQuery, |
150 filteredDataMatch, |
156 filteredDataMatch, |
151 isSearchInGroup, |
157 aIsSearchInGroup, |
152 aContactsInGroup); |
158 aContactsInGroup); |
153 |
159 |
154 // If alphabetical sorting, get the results for this datastore |
160 // If alphabetical sorting, get the results for this datastore |
155 if ( sortType == EAlphabetical ) |
161 if ( sortType == EAlphabetical ) |
156 { |
162 { |
157 filterHelper->GetResults(*(iSearchResultsArr[dsIndex])); |
163 filterHelper->GetResults(*(iSearchResultsArr[dsIndex])); |
158 } |
164 } |
159 |
165 |
160 elements.Reset(); |
166 elements.Reset(); |
161 supportedDataFields.Reset(); |
167 CleanupStack::PopAndDestroy( &supportedDataFields ); // Close |
162 } |
168 } |
163 |
169 |
164 aDataStores.ResetAndDestroy(); |
170 CleanupStack::PopAndDestroy( &elements ); // Close |
165 requiredDataFields.Reset(); |
171 CleanupStack::PopAndDestroy( &requiredDataFields ); // Close |
|
172 CleanupStack::PopAndDestroy( &dataStores ); // ResetAndDestroy |
166 |
173 |
167 // If alphabetical sorting, merge the result sets of all datastores |
174 // If alphabetical sorting, merge the result sets of all datastores |
168 if ( sortType == EAlphabetical ) |
175 if ( sortType == EAlphabetical ) |
169 { |
176 { |
170 // Merge the result sets of individual datastores alphabetically |
177 // Merge the result sets of individual datastores alphabetically |
171 CPcsAlgorithm1Utils::FormCompleteSearchResultsL(iSearchResultsArr, |
178 CPcsAlgorithm1Utils::FormCompleteSearchResultsL(iSearchResultsArr, |
172 searchResults); |
179 aSearchResults); |
173 } |
180 } |
174 else |
181 else |
175 { |
182 { |
176 // Results are already sorted pattern based |
183 // Results are already sorted pattern based |
177 filterHelper->GetResults(searchResults); |
184 filterHelper->GetResults(aSearchResults); |
178 } |
185 } |
179 |
186 |
180 // Get the sorted match sequence list |
187 // Get the sorted match sequence list |
181 filterHelper->GetPatternsL(searchSeqs); |
188 filterHelper->GetPatternsL(aSearchSeqs); |
182 |
189 |
183 PRINT1 ( _L("CPcsAlgorithm1Helper::SearchSingleL: Number of search results = %d"), searchResults.Count() ); |
190 PRINT1 ( _L("CPcsAlgorithm1Helper::SearchSingleL: Number of search results = %d"), aSearchResults.Count() ); |
184 |
191 |
185 // Cleanup |
192 // Cleanup |
186 for ( TInt i = 0; i < iSearchResultsArr.Count(); i++ ) |
193 for ( TInt i = 0; i < iSearchResultsArr.Count(); i++ ) |
187 { |
194 { |
188 iSearchResultsArr[i]->Reset(); |
195 iSearchResultsArr[i]->Reset(); |
189 delete iSearchResultsArr[i]; |
196 } |
190 iSearchResultsArr[i] = NULL; |
197 iSearchResultsArr.ResetAndDestroy(); |
191 } |
198 |
192 iSearchResultsArr.Reset(); |
199 CleanupStack::PopAndDestroy( filterHelper ); |
193 |
|
194 delete filterHelper; |
|
195 |
200 |
196 __LATENCY_MARKEND ( _L("CPcsAlgorithm1Helper::SearchSingleL") ); |
201 __LATENCY_MARKEND ( _L("CPcsAlgorithm1Helper::SearchSingleL") ); |
197 |
202 |
198 PRINT ( _L("End CPcsAlgorithm1Helper::SearchSingleL") ); |
203 PRINT ( _L("End CPcsAlgorithm1Helper::SearchSingleL") ); |
199 } |
204 } |
201 // ---------------------------------------------------------------------------- |
206 // ---------------------------------------------------------------------------- |
202 // CPcsAlgorithm1Helper::FilterResultsSingleL |
207 // CPcsAlgorithm1Helper::FilterResultsSingleL |
203 // Subset search function |
208 // Subset search function |
204 // ---------------------------------------------------------------------------- |
209 // ---------------------------------------------------------------------------- |
205 void CPcsAlgorithm1Helper::FilterResultsSingleL(CPcsAlgorithm1FilterHelper* aAlgorithmFilterHelper, |
210 void CPcsAlgorithm1Helper::FilterResultsSingleL(CPcsAlgorithm1FilterHelper* aAlgorithmFilterHelper, |
206 RPointerArray<CPcsPoolElement>& searchSet, |
211 RPointerArray<CPcsPoolElement>& aSearchSet, |
207 CPsQuery& aPsQuery, |
212 CPsQuery& aPsQuery, |
208 TUint8 aFilteredDataMatch, |
213 TUint8 aFilteredDataMatch, |
209 TBool isSearchInGroup, |
214 TBool aIsSearchInGroup, |
210 RArray<TInt>& aContactsInGroup) |
215 RArray<TInt>& aContactsInGroup) |
211 { |
216 { |
212 PRINT ( _L("Enter CPcsAlgorithm1Helper::FilterResultsSingleL") ); |
217 PRINT ( _L("Enter CPcsAlgorithm1Helper::FilterResultsSingleL") ); |
213 |
218 |
214 __LATENCY_MARK ( _L("CPcsAlgorithm1Helper::FilterResultsSingleL") ); |
219 __LATENCY_MARK ( _L("CPcsAlgorithm1Helper::FilterResultsSingleL") ); |
221 |
226 |
222 PRINT1 ( _L("CPcsAlgorithm1Helper::FilterResultsSingleL: char-and-key string for the query is \"%S\""), |
227 PRINT1 ( _L("CPcsAlgorithm1Helper::FilterResultsSingleL: char-and-key string for the query is \"%S\""), |
223 &queryAsDes ); |
228 &queryAsDes ); |
224 |
229 |
225 // Parse thru each search set elements and filter the results |
230 // Parse thru each search set elements and filter the results |
226 for ( TInt index = 0; index < searchSet.Count(); index++ ) |
231 for ( TInt index = 0; index < aSearchSet.Count(); index++ ) |
227 { |
232 { |
228 CPcsPoolElement* poolElement = static_cast<CPcsPoolElement*>(searchSet[index]); |
233 CPcsPoolElement* poolElement = static_cast<CPcsPoolElement*>(aSearchSet[index]); |
229 CPsData* psData = poolElement->GetPsData(); |
234 CPsData* psData = poolElement->GetPsData(); |
230 psData->ClearDataMatches(); |
235 psData->ClearDataMatches(); |
231 RPointerArray<TDesC> tempMatchSeq; |
236 RPointerArray<TDesC> tempMatchSeq; |
|
237 CleanupResetAndDestroyPushL( tempMatchSeq ); |
232 TBool isAdded = EFalse; |
238 TBool isAdded = EFalse; |
233 |
239 |
234 // Parse thru each data and filter the results |
240 // Parse thru each data and filter the results |
235 for ( TInt dataIndex = 0; dataIndex < psData->DataElementCount(); dataIndex++ ) |
241 for ( TInt dataIndex = 0; dataIndex < psData->DataElementCount(); dataIndex++ ) |
236 { |
242 { |
237 // Filter off data fields not required in search |
243 // Filter off data fields not required in search |
238 TReal bitIndex; |
244 TUint8 bitIndex = 1 << dataIndex; |
239 Math::Pow(bitIndex, 2, dataIndex); |
245 |
240 |
246 TUint8 filter = bitIndex & aFilteredDataMatch; |
241 TUint8 filter = (TUint8)bitIndex & aFilteredDataMatch; |
|
242 if ( filter == 0x0 ) |
247 if ( filter == 0x0 ) |
243 { |
248 { |
244 // Move to next data |
249 // Move to next data |
245 continue; |
250 continue; |
246 } |
251 } |
247 |
252 |
248 if ( poolElement->IsDataMatch(dataIndex) ) |
253 if ( poolElement->IsDataMatch(dataIndex) ) |
249 { |
254 { |
250 TLex lex(psData->Data(dataIndex)->Des()); |
255 TLex lex( *psData->Data(dataIndex) ); |
251 |
256 |
252 // First word |
257 // First word |
253 TPtrC token = lex.NextToken(); |
258 TPtrC token = lex.NextToken(); |
254 |
259 |
255 // Search thru multiple words |
260 // Search thru multiple words |