predictivesearch/PcsAlgorithm/Algorithm1/src/CPcsAlgorithm1Helper.cpp
branchRCL_3
changeset 21 b3431bff8c19
parent 15 e8e3147d53eb
child 64 c1e8ba0c2b16
equal deleted inserted replaced
15:e8e3147d53eb 21:b3431bff8c19
   130     for ( TInt dsIndex = 0; 
   130     for ( TInt dsIndex = 0; 
   131           dsIndex < dataStores.Count();
   131           dsIndex < dataStores.Count();
   132           dsIndex++ )
   132           dsIndex++ )
   133     {
   133     {
   134         RPointerArray<CPsData> *temp = new (ELeave) RPointerArray<CPsData> ();
   134         RPointerArray<CPsData> *temp = new (ELeave) RPointerArray<CPsData> ();
   135         iSearchResultsArr.Append(temp);
   135         CleanupStack::PushL( temp );
       
   136         iSearchResultsArr.AppendL( temp );
       
   137         CleanupStack::Pop( temp );
   136 
   138 
   137         // Get the contents for this data store
   139         // Get the contents for this data store
   138         TInt arrayIndex = iAlgorithm->GetCacheIndex(*(dataStores[dsIndex]));
   140         TInt arrayIndex = iAlgorithm->GetCacheIndex(*(dataStores[dsIndex]));
   139         if ( arrayIndex < 0 ) continue;
   141         if ( arrayIndex < 0 ) continue;
   140         CPcsCache* cache = iAlgorithm->GetCache(arrayIndex);
   142         CPcsCache* cache = iAlgorithm->GetCache(arrayIndex);
   144         RArray<TInt> supportedDataFields;
   146         RArray<TInt> supportedDataFields;
   145         CleanupClosePushL( supportedDataFields );
   147         CleanupClosePushL( supportedDataFields );
   146         cache->GetDataFields(supportedDataFields);
   148         cache->GetDataFields(supportedDataFields);
   147 
   149 
   148         // Get the filtered data fields for this data store
   150         // Get the filtered data fields for this data store
   149         TUint8 filteredDataMatch = FilterDataFieldsL(requiredDataFields,
   151         TUint8 filteredDataMatch = CPcsAlgorithm1Utils::FilterDataFieldsL(requiredDataFields,
   150                                                      supportedDataFields);
   152                                                                           supportedDataFields);
   151 
   153 
   152         // Perform filtering
   154         // Perform filtering
   153         FilterResultsSingleL(filterHelper,
   155         FilterResultsSingleL(filterHelper,
   154                              elements,
   156                              elements,
   155                              aPsQuery,
   157                              aPsQuery,
   231     for ( TInt index = 0; index < aSearchSet.Count(); index++ )
   233     for ( TInt index = 0; index < aSearchSet.Count(); index++ )
   232     {
   234     {
   233         CPcsPoolElement* poolElement = static_cast<CPcsPoolElement*>(aSearchSet[index]);
   235         CPcsPoolElement* poolElement = static_cast<CPcsPoolElement*>(aSearchSet[index]);
   234         CPsData* psData = poolElement->GetPsData();
   236         CPsData* psData = poolElement->GetPsData();
   235         psData->ClearDataMatches();
   237         psData->ClearDataMatches();
       
   238         
       
   239         // Skip this contact if performing group search and this contact doesn't
       
   240         // belong to the group
       
   241         if ( aIsSearchInGroup && aContactsInGroup.Find(psData->Id()) == KErrNotFound )
       
   242             {
       
   243             continue;
       
   244             }
       
   245         
   236         RPointerArray<TDesC> tempMatchSeq;
   246         RPointerArray<TDesC> tempMatchSeq;
   237         CleanupResetAndDestroyPushL( tempMatchSeq );
   247         CleanupResetAndDestroyPushL( tempMatchSeq );
   238         TBool isAdded = EFalse;
   248         TBool isAdded = EFalse;
   239 
   249 
   240         // Parse thru each data and filter the results
   250         // Parse thru each data and filter the results
   269                         psData->SetDataMatch(dataIndex);
   279                         psData->SetDataMatch(dataIndex);
   270                         isAdded = ETrue;
   280                         isAdded = ETrue;
   271 
   281 
   272                         // Extract matched character sequence
   282                         // Extract matched character sequence
   273                         TInt len = queryAsDes.Length();
   283                         TInt len = queryAsDes.Length();
   274                         HBufC* seq = HBufC::NewLC(len);
   284                         TPtrC seq = token.Left(len);
   275                         *seq = token.Mid(0, len);
   285                         CPcsAlgorithm1Utils::AppendMatchToSeqL( tempMatchSeq, seq );
   276                         seq->Des().UpperCase();
       
   277 
       
   278                         TIdentityRelation<TDesC> rule(CPcsAlgorithm1Utils::CompareExact);
       
   279                         if ( tempMatchSeq.Find(seq, rule) == KErrNotFound )
       
   280                         {
       
   281                             tempMatchSeq.Append(seq);
       
   282                             CleanupStack::Pop(seq);
       
   283                         }
       
   284                         else
       
   285                         {
       
   286                             CleanupStack::PopAndDestroy(seq);
       
   287                         }
       
   288                     }
   286                     }
   289                     // Next word
   287                     // Next word
   290                     token.Set(lex.NextToken());
   288                     token.Set(lex.NextToken());
   291                 }
   289                 }
   292             }
   290             }
   293         }
   291         }
   294 
   292 
   295         // Add the result
   293         // Add the result
   296         if ( isAdded )
   294         if ( isAdded )
   297         {
   295         {
   298             if ( aIsSearchInGroup )
   296             aAlgorithmFilterHelper->AddL(psData,tempMatchSeq);
   299             {
       
   300                 if ( aContactsInGroup.Find(psData->Id()) != KErrNotFound )
       
   301                 {
       
   302                     aAlgorithmFilterHelper->AddL(psData,tempMatchSeq);
       
   303                 }
       
   304             }
       
   305             else
       
   306             {
       
   307                 aAlgorithmFilterHelper->AddL(psData,tempMatchSeq);
       
   308             }
       
   309         }
   297         }
   310 
   298 
   311         // Cleanup the match sequence array as
   299         // Cleanup the match sequence array as
   312         // they are stored in pattern details structure
   300         // they are stored in pattern details structure
   313         CleanupStack::PopAndDestroy( &tempMatchSeq ); // ResetAndDestroy
   301         CleanupStack::PopAndDestroy( &tempMatchSeq ); // ResetAndDestroy
   364 
   352 
   365             // Add the match location to the data structure array
   353             // Add the match location to the data structure array
   366             aMatchLocation.Append(tempLocation);
   354             aMatchLocation.Append(tempLocation);
   367 
   355 
   368             // Add the sequence to the match sequence
   356             // Add the sequence to the match sequence
   369             HBufC* seq = HBufC::NewLC(len);
   357             TPtrC seq = token.Left(len);
   370             *seq = token.Mid(0, len);
   358             CPcsAlgorithm1Utils::AppendMatchToSeqL( aMatchSet, seq );
   371             seq->Des().UpperCase();
       
   372 
       
   373             TIdentityRelation<TDesC> rule(CPcsAlgorithm1Utils::CompareExact);
       
   374             if ( aMatchSet.Find(seq, rule) == KErrNotFound )
       
   375             {
       
   376                 aMatchSet.Append(seq);
       
   377                 CleanupStack::Pop();
       
   378             }
       
   379             else
       
   380             {
       
   381                 CleanupStack::PopAndDestroy();
       
   382             }
       
   383         }
   359         }
   384 
   360 
   385         // Next word
   361         // Next word
   386         token.Set(lex.NextToken());
   362         token.Set(lex.NextToken());
   387         beg = lex.Offset() - token.Length();  // start index of next word
   363         beg = lex.Offset() - token.Length();  // start index of next word
   402     // Sort the search seqs
   378     // Sort the search seqs
   403     TLinearOrder<TDesC> rule( CPcsAlgorithm1Utils::CompareCollate );
   379     TLinearOrder<TDesC> rule( CPcsAlgorithm1Utils::CompareCollate );
   404     aSearchSeqs.Sort(rule);
   380     aSearchSeqs.Sort(rule);
   405 }
   381 }
   406 
   382 
   407 // ----------------------------------------------------------------------------
       
   408 // CPcsAlgorithm1Helper::FilterDataFieldsL()
       
   409 // Constructs a bit pattern using the required/supported data fields
       
   410 // For example, 6, 4 and 27 are supported fields <-- 00000111
       
   411 //              6 and 4 are required fields      <-- 00000011
       
   412 // Bit pattern returned is 00000011.
       
   413 // ----------------------------------------------------------------------------
       
   414 TUint8 CPcsAlgorithm1Helper::FilterDataFieldsL(RArray<TInt>& aRequiredDataFields,
       
   415                                                RArray<TInt>& aSupportedDataFields)
       
   416 {
       
   417     TUint8 filteredMatch = 0x0;
       
   418 
       
   419     for ( TInt i = 0; i < aSupportedDataFields.Count(); i++ )
       
   420     {
       
   421         for ( TInt j = 0; j < aRequiredDataFields.Count(); j++ )
       
   422         {
       
   423             if ( aSupportedDataFields[i] == aRequiredDataFields[j] )
       
   424             {
       
   425                 TUint8 val = 1 << i;
       
   426                 filteredMatch |= val;
       
   427             }
       
   428         }
       
   429     }
       
   430 
       
   431     return filteredMatch;
       
   432 }
       
   433 
       
   434 // End of file
   383 // End of file