predictivesearch/PcsAlgorithm/Algorithm2/src/CPcsAlgorithm2MultiSearchHelper.cpp
branchRCL_3
changeset 74 6b5524b4f673
parent 63 f4a778e096c2
child 85 38bb213f60ba
equal deleted inserted replaced
68:9da50d567e3c 74:6b5524b4f673
   266 
   266 
   267     PRINT ( _L("End CPcsAlgorithm2MultiSearchHelper::SearchMatchSeqMultiL") );
   267     PRINT ( _L("End CPcsAlgorithm2MultiSearchHelper::SearchMatchSeqMultiL") );
   268     }
   268     }
   269 
   269 
   270 // ----------------------------------------------------------------------------
   270 // ----------------------------------------------------------------------------
       
   271 // CPcsAlgorithm2MultiSearchHelper::LookupMatchL
       
   272 // ----------------------------------------------------------------------------
       
   273 void CPcsAlgorithm2MultiSearchHelper::LookupMatchL( CPsQuery& aSearchQuery,
       
   274     const TDesC& aData, TDes& aMatchedData )
       
   275     {
       
   276     _LIT( KSpace, " " );
       
   277     aMatchedData.Zero();
       
   278     RPointerArray<CPsQuery> queryList = MultiQueryL( aSearchQuery );
       
   279     CleanupResetAndDestroyPushL( queryList );
       
   280     // Convert the individual queries to string form
       
   281     RPointerArray<CPsQuery> mySearchQuery;
       
   282     CleanupResetAndDestroyPushL( mySearchQuery );
       
   283 
       
   284     // Remember a temporary copy of query list
       
   285     // Copy the content of searchQuery
       
   286     const TInt searchQueryCount = queryList.Count();
       
   287     for (TInt i = 0; i < searchQueryCount; i++ )
       
   288         {
       
   289         CPsQuery* tempQuery = CPsQuery::NewL();
       
   290         CleanupStack::PushL( tempQuery );
       
   291         iAlgorithm->FindUtilECE()->GetPartOfQueryL( *(queryList[i]), 0,
       
   292             queryList[i]->Count() - 1, *tempQuery );
       
   293         mySearchQuery.AppendL( tempQuery );
       
   294         CleanupStack::Pop( tempQuery ); // ownership transferred
       
   295         }
       
   296 
       
   297     // Sort the query items according to the length of each query 
       
   298     TLinearOrder<CPsQuery> rule( CPcsAlgorithm2Utils::CompareLength );
       
   299     mySearchQuery.Sort( rule );
       
   300 
       
   301     // To hold the match results
       
   302     RPointerArray<TDesC> tmpMatchSet;
       
   303     CleanupResetAndDestroyPushL( tmpMatchSet );
       
   304 
       
   305     TBool isMatch = ETrue;
       
   306     TInt wordMatches = 0;
       
   307 
       
   308     // Reset iWordMatches to zero 
       
   309     ClearWordMatches();
       
   310 
       
   311     // Check for each query atleast one data element matches
       
   312     // Loop from the last query so that longest match is seen first
       
   313     for (TInt queryIndex = mySearchQuery.Count() - 1; queryIndex >= 0; queryIndex-- )
       
   314         {
       
   315         TBool queryMatch = EFalse;
       
   316         CPsQuery* tmpPsQuery = mySearchQuery[queryIndex];
       
   317 
       
   318         TInt wordIndex = -1;
       
   319         TLex lex( aData );
       
   320 
       
   321         // First word
       
   322         TPtrC tmpData = lex.NextToken();
       
   323 
       
   324         // Search thru multiple words
       
   325         while (tmpData.Length() != 0 )
       
   326             {
       
   327             wordIndex++;
       
   328 
       
   329             // Compare the data against query
       
   330             TBool matched = iAlgorithm->FindUtilECE()->MatchRefineL( tmpData,
       
   331                 *tmpPsQuery );
       
   332 
       
   333             if ( matched )
       
   334                 {
       
   335                 // Perform two checks.
       
   336                 // 1. Ensure that the word is not matched against any previous query
       
   337                 // 2. If it is the first match to the query
       
   338                 TBool isWordMatch = IsWordMatch( 0, wordIndex );
       
   339 
       
   340                 // Check if the current word is not matched to any query
       
   341                 // For example, there is a contact named "abc a" and query is key2
       
   342                 // The key2 could match the first and second 'a'. So it is required to 
       
   343                 // check if the current word has aready been matched before.
       
   344 
       
   345                 if ( !isWordMatch )
       
   346                     {
       
   347                     // Check if no word is matched for this query till now
       
   348                     if ( !queryMatch )
       
   349                         {
       
   350                         wordMatches++;
       
   351                         queryMatch = ETrue;
       
   352                         SetWordMap( 0, wordIndex );
       
   353                         // Extract matched character sequence and fill in temp array
       
   354                         TInt len = tmpPsQuery->Count();
       
   355                         if ( iAlgorithm->FindUtilECE()->IsChineseWordIncluded(
       
   356                             tmpData ) )
       
   357                             {
       
   358                             // A Chinese word could be matched by serveral keys
       
   359                             // It is hard to know the matched query length. So set it to 1
       
   360                             // as a trick result
       
   361                             len = 1;
       
   362                             }
       
   363 
       
   364                         TPtrC seq = tmpData.Left( len );
       
   365                         CPcsAlgorithm2Utils::AppendMatchToSeqL( tmpMatchSet,
       
   366                             seq );
       
   367                         }
       
   368                     }
       
   369                 }
       
   370 
       
   371             // Next word
       
   372             tmpData.Set( lex.NextToken() );
       
   373             }
       
   374 
       
   375         // No data element matches the query. Ignore this result.
       
   376         if ( queryMatch == EFalse )
       
   377             {
       
   378             isMatch = EFalse;
       
   379             break;
       
   380             }
       
   381         }
       
   382 
       
   383     // If match add the element to the result set
       
   384     //  And before adding to the result set, check if there is atleast one match per query
       
   385     if ( isMatch && wordMatches >= mySearchQuery.Count() )
       
   386         {
       
   387         const TInt matchCount = tmpMatchSet.Count();
       
   388         for (TInt i = 0; i < matchCount; i++ )
       
   389             {
       
   390             aMatchedData.Append( *tmpMatchSet[i] );
       
   391             aMatchedData.Append( KSpace );
       
   392             }
       
   393         aMatchedData.TrimRight();
       
   394         }
       
   395 
       
   396     CleanupStack::PopAndDestroy( &tmpMatchSet ); // ResetAndDestroy
       
   397     CleanupStack::PopAndDestroy( &mySearchQuery ); // ResetAndDestroy
       
   398     CleanupStack::PopAndDestroy( &queryList ); // ResetAndDestroy
       
   399     }
       
   400 
       
   401 // ----------------------------------------------------------------------------
   271 // CPcsAlgorithm2MultiSearchHelper::FilterResultsMultiL
   402 // CPcsAlgorithm2MultiSearchHelper::FilterResultsMultiL
   272 // Subset search function. Refer the above function for more description.
   403 // Subset search function. Refer the above function for more description.
   273 // ----------------------------------------------------------------------------
   404 // ----------------------------------------------------------------------------
   274 void CPcsAlgorithm2MultiSearchHelper::FilterResultsMultiL(CPcsAlgorithm2FilterHelper* aAlgorithmFilterHelper, 
   405 void CPcsAlgorithm2MultiSearchHelper::FilterResultsMultiL(CPcsAlgorithm2FilterHelper* aAlgorithmFilterHelper, 
   275                                                           RPointerArray<CPcsPoolElement>& aSearchSet,
   406                                                           RPointerArray<CPcsPoolElement>& aSearchSet,