predictivesearch/PcsAlgorithm/Algorithm1/src/CPcsAlgorithm1Helper.cpp
branchRCL_3
changeset 3 04ab22b956c2
parent 0 e686773b3f54
child 15 e8e3147d53eb
equal deleted inserted replaced
0:e686773b3f54 3:04ab22b956c2
    29 #include "CPsQuery.h"
    29 #include "CPsQuery.h"
    30 #include "CPsQueryItem.h"
    30 #include "CPsQueryItem.h"
    31 #include "CPsDataPluginInterface.h"
    31 #include "CPsDataPluginInterface.h"
    32 #include "CPcsPoolElement.h"
    32 #include "CPcsPoolElement.h"
    33 
    33 
    34 // Compare functions
       
    35 TBool Compare1 ( const TDesC& aFirst, const TDesC& aSecond )
       
    36 {
       
    37     return aFirst == aSecond;
       
    38 }
       
    39 
       
    40 TBool Compare2 ( const TDesC& aFirst, const TDesC& aSecond )
       
    41 {
       
    42     return CPcsAlgorithm1Utils::MyCompareC(aFirst, aSecond);
       
    43 }
       
    44 
       
    45 // ============================== MEMBER FUNCTIONS ============================
    34 // ============================== MEMBER FUNCTIONS ============================
    46 
    35 
    47 // ----------------------------------------------------------------------------
    36 // ----------------------------------------------------------------------------
    48 // CPcsAlgorithm1Helper::NewL
    37 // CPcsAlgorithm1Helper::NewL
    49 // Two Phase Construction
    38 // Two Phase Construction
   268                 {
   257                 {
   269                     // Convert the data to char-and-key string
   258                     // Convert the data to char-and-key string
   270                     TBuf<KPsQueryMaxLen> dataWithKeys;
   259                     TBuf<KPsQueryMaxLen> dataWithKeys;
   271                     iKeyMap->GetMixedKeyStringForDataL( aPsQuery, token, dataWithKeys );
   260                     iKeyMap->GetMixedKeyStringForDataL( aPsQuery, token, dataWithKeys );
   272 
   261 
   273                     // MyCompareC is case insensitive.
   262                     if ( CPcsAlgorithm1Utils::MyCompareKeyAndString(dataWithKeys, queryAsDes, aPsQuery) )
   274                     // We have some cases that key "Z" (uppercase) is mapping chars "Zz...."
       
   275                     // and key "z" (lowercase) is mapping chars ".," or "Ää".
       
   276                     // The comparison of "Z" and "z" should fail for the keys, that's why we use MyCompareK.
       
   277                     if ( ( CPcsAlgorithm1Utils::MyCompareK(dataWithKeys, queryAsDes, aPsQuery) ) &&
       
   278                          ( CPcsAlgorithm1Utils::MyCompareC(dataWithKeys.Left(queryAsDes.Length()), queryAsDes) == 0 ) )
       
   279                     {
   263                     {
   280                         psData->SetDataMatch(dataIndex);
   264                         psData->SetDataMatch(dataIndex);
   281                         isAdded = ETrue;
   265                         isAdded = ETrue;
   282 
   266 
   283                         // Extract matched character sequence
   267                         // Extract matched character sequence
   284                         TInt len = queryAsDes.Length();
   268                         TInt len = queryAsDes.Length();
   285                         HBufC* seq = HBufC::NewLC(len);
   269                         HBufC* seq = HBufC::NewLC(len);
   286                         *seq = token.Mid(0, len);
   270                         *seq = token.Mid(0, len);
   287                         seq->Des().UpperCase();
   271                         seq->Des().UpperCase();
   288 
   272 
   289                         TIdentityRelation<TDesC> rule(Compare1);
   273                         TIdentityRelation<TDesC> rule(CPcsAlgorithm1Utils::CompareExact);
   290                         if ( tempMatchSeq.Find(seq, rule) == KErrNotFound )
   274                         if ( tempMatchSeq.Find(seq, rule) == KErrNotFound )
   291                         {
   275                         {
   292                             tempMatchSeq.Append(seq);
   276                             tempMatchSeq.Append(seq);
   293                             CleanupStack::Pop();
   277                             CleanupStack::Pop();
   294                         }
   278                         }
   353     TInt beg = lex.Offset() - token.Length();  // start index of match sequence
   337     TInt beg = lex.Offset() - token.Length();  // start index of match sequence
   354 
   338 
   355     // Search thru multiple words
   339     // Search thru multiple words
   356     while ( token.Length() != 0 )
   340     while ( token.Length() != 0 )
   357     {
   341     {
   358          HBufC* data = HBufC::NewLC(token.Length());
   342         HBufC* data = HBufC::NewLC(token.Length());
   359          TPtr dataPtr(data->Des());
   343         TPtr dataPtr(data->Des());
   360          iKeyMap->GetMixedKeyStringForDataL( aPsQuery, token, dataPtr );
   344         iKeyMap->GetMixedKeyStringForDataL( aPsQuery, token, dataPtr );
   361 
   345 
   362          // MyCompareC is case insensitive.
   346         if ( CPcsAlgorithm1Utils::MyCompareKeyAndString(dataPtr, *queryAsDes, aPsQuery) )
   363          // We have some cases that key "Z" (uppercase) is mapping chars "Zz...."
   347         {
   364          // and key "z" (lowercase) is mapping chars ".," or "Ää".
       
   365          // The comparison of "Z" and "z" should fail for the keys, that's why we use MyCompareK.
       
   366          if ( ( CPcsAlgorithm1Utils::MyCompareK(dataPtr, *queryAsDes, aPsQuery) ) &&
       
   367               ( CPcsAlgorithm1Utils::MyCompareC(dataPtr.Left(queryAsDes->Length()), *queryAsDes) == 0 ) )
       
   368          {
       
   369             TInt len = queryAsDes->Length();
   348             TInt len = queryAsDes->Length();
   370 
   349 
   371             TPsMatchLocation tempLocation;
   350             TPsMatchLocation tempLocation;
   372 
   351 
   373             // check for directionality of the text
   352             // check for directionality of the text
   384             // Add the sequence to the match sequence
   363             // Add the sequence to the match sequence
   385             HBufC* seq = HBufC::NewLC(len);
   364             HBufC* seq = HBufC::NewLC(len);
   386             *seq = token.Mid(0, len);
   365             *seq = token.Mid(0, len);
   387             seq->Des().UpperCase();
   366             seq->Des().UpperCase();
   388 
   367 
   389             TIdentityRelation<TDesC> rule(Compare1);
   368             TIdentityRelation<TDesC> rule(CPcsAlgorithm1Utils::CompareExact);
   390             if ( aMatchSet.Find(seq, rule) == KErrNotFound )
   369             if ( aMatchSet.Find(seq, rule) == KErrNotFound )
   391             {
   370             {
   392                 aMatchSet.Append(seq);
   371                 aMatchSet.Append(seq);
   393                 CleanupStack::Pop();
   372                 CleanupStack::Pop();
   394             }
   373             }
   395             else
   374             else
   396             {
   375             {
   397                 CleanupStack::PopAndDestroy();
   376                 CleanupStack::PopAndDestroy();
   398             }
   377             }
   399          }
   378         }
   400 
   379 
   401          // Next word
   380         // Next word
   402          token.Set(lex.NextToken());
   381         token.Set(lex.NextToken());
   403          beg = lex.Offset() - token.Length();  // start index of next word
   382         beg = lex.Offset() - token.Length();  // start index of next word
   404          CleanupStack::PopAndDestroy(); //data
   383         CleanupStack::PopAndDestroy(); //data
   405      }
   384     }
   406 
   385 
   407     CleanupStack::PopAndDestroy( queryAsDes );
   386     CleanupStack::PopAndDestroy( queryAsDes );
   408 
   387 
   409     PRINT ( _L("End CPcsAlgorithm1Helper::SearchMatchSeqL") );
   388     PRINT ( _L("End CPcsAlgorithm1Helper::SearchMatchSeqL") );
   410 }
   389 }
   414 //
   393 //
   415 // ----------------------------------------------------------------------------
   394 // ----------------------------------------------------------------------------
   416 void  CPcsAlgorithm1Helper::SortSearchSeqsL(RPointerArray<TDesC>& aSearchSeqs)
   395 void  CPcsAlgorithm1Helper::SortSearchSeqsL(RPointerArray<TDesC>& aSearchSeqs)
   417 {
   396 {
   418     // Sort the search seqs
   397     // Sort the search seqs
   419     TLinearOrder<TDesC> rule( Compare2 );
   398     TLinearOrder<TDesC> rule( CPcsAlgorithm1Utils::CompareCollate );
   420     aSearchSeqs.Sort(rule);
   399     aSearchSeqs.Sort(rule);
   421 }
   400 }
   422 
   401 
   423 // ----------------------------------------------------------------------------
   402 // ----------------------------------------------------------------------------
   424 // CPcsAlgorithm1Helper::FilterDataFieldsL()
   403 // CPcsAlgorithm1Helper::FilterDataFieldsL()