diff -r 6b5524b4f673 -r 38bb213f60ba predictivesearch/PcsAlgorithm/Algorithm2/src/CPcsAlgorithm2Utils.cpp --- a/predictivesearch/PcsAlgorithm/Algorithm2/src/CPcsAlgorithm2Utils.cpp Wed Sep 15 11:56:55 2010 +0300 +++ b/predictivesearch/PcsAlgorithm/Algorithm2/src/CPcsAlgorithm2Utils.cpp Wed Oct 13 14:15:33 2010 +0300 @@ -18,7 +18,6 @@ // INCLUDES #include "CPcsAlgorithm2Utils.h" #include "CPsData.h" -#include "CPsQuery.h" #include "CPcsDefs.h" #include "CPcsCache.h" #include @@ -34,15 +33,16 @@ // Merges all the respective data store result sets to single set in sorted order. // ---------------------------------------------------------------------------- void CPcsAlgorithm2Utils::FormCompleteSearchResultsL(RPointerArray& aSearchResultsArr, - RPointerArray& aSearchResults) + RPointerArray& SearchResults) { + CleanupClosePushL( SearchResults ); + TInt maxIndex = 0; TInt maxValue = aSearchResultsArr[maxIndex]->Count(); - TLinearOrder rule(CPcsAlgorithm2Utils::CompareDataBySortOrderL); + TLinearOrder rule(CPcsAlgorithm2Utils::CompareDataBySortOrder); // Find the largest array in aSearchResultsArr - const TInt searchResultsArrCount = aSearchResultsArr.Count(); - for (TInt i = 1; i < searchResultsArrCount; i++) + for (TInt i = 1; i < aSearchResultsArr.Count(); i++) { if (aSearchResultsArr[i]->Count() > maxValue) { @@ -52,15 +52,13 @@ } // Assign the largets array to searchresults - const TInt cnt = aSearchResultsArr[maxIndex]->Count(); - for (TInt i = 0; i < cnt; i++) + for (TInt i = 0; i < aSearchResultsArr[maxIndex]->Count(); i++) { - aSearchResults.Append((*(aSearchResultsArr[maxIndex]))[i]); + SearchResults.Append((*(aSearchResultsArr[maxIndex]))[i]); } // Merge the remaining result arrays to the largest array in sequential order - - for (TInt i = 0; i < searchResultsArrCount; i++) + for (TInt i = 0; i < aSearchResultsArr.Count(); i++) { // Check if we are not copying again the largest array if ((i != maxIndex) && ((aSearchResultsArr[i])->Count() != 0)) @@ -68,10 +66,11 @@ TInt numElements = (aSearchResultsArr[i])->Count(); for (TInt j = 0; j < numElements; j++) { - aSearchResults.InsertInOrderAllowRepeatsL((*(aSearchResultsArr[i]))[j], rule); + SearchResults.InsertInOrderAllowRepeatsL((*(aSearchResultsArr[i]))[j], rule); } } } + CleanupStack::Pop(); } // ---------------------------------------------------------------------------- @@ -99,149 +98,100 @@ } // ---------------------------------------------------------------------------- -// CPcsAlgorithm2Utils::CompareDataBySortOrderL() +// CPcsAlgorithm2Utils::CompareDataBySortOrder() // TLinearOrder rule for comparison of data objects // ---------------------------------------------------------------------------- -TInt CPcsAlgorithm2Utils::CompareDataBySortOrderL(const CPsData& aObject1, - const CPsData& aObject2) +TInt CPcsAlgorithm2Utils::CompareDataBySortOrder(const CPsData& aObject1, + const CPsData& aObject2) { - TInt compareRes = 0; - - if( CPsData::CompareById(aObject1, aObject2) ) - { - return compareRes; - } + _LIT(KSpace, " "); // Fetch the cache list stored in TLS to recover the sort order typedef RPointerArray PTR; - PTR* pcsCache = static_cast(Dll::Tls()); - User::LeaveIfNull(pcsCache); + PTR* pcsCache = static_cast (Dll::Tls()); - CPcsCache* cache1 = (*pcsCache)[aObject1.UriId()]; - CPcsCache* cache2 = (*pcsCache)[aObject2.UriId()]; - RArray indexOrder1; - RArray indexOrder2; + // Data1 + TBuf<255> data1(KNullDesC); + TInt uriId1 = aObject1.UriId(); + CPcsCache* cache = (*pcsCache)[uriId1]; + + RArray indexOrder; // Get the index order based on sort order from the cache - cache1->GetIndexOrder(indexOrder1); - CleanupClosePushL(indexOrder1); - cache2->GetIndexOrder(indexOrder2); - CleanupClosePushL(indexOrder2); + cache->GetIndexOrder(indexOrder); - // Check if Sort Order is identical (it must be for same cache) - TBool sameIndexOrder = ETrue; - if ( indexOrder1.Count() != indexOrder2.Count() ) + // Append sort order elements first + for (int i = 0; i < indexOrder.Count(); i++) { - sameIndexOrder = EFalse; - } - else - { - for ( TInt i = 0; i < indexOrder1.Count(); i++ ) + TInt index = indexOrder[i]; + if (index < aObject1.DataElementCount() && aObject1.Data(index)) { - if (indexOrder1[i] != indexOrder2[i]) - { - sameIndexOrder = EFalse; - break; - } + // Trim the unnecessary white spaces/special chars before we compare + TBuf<255> str(KNullDesC); + + str = aObject1.Data(index)->Des(); + CPcsAlgorithm2Utils::MyTrim(str); + + data1 += str; + data1 += KSpace; } } - // Sort Orders among diffent caches should be the same, anyway - // if caches and SO are different we compare by cache URI index - if (!sameIndexOrder) - { - compareRes = aObject1.UriId() - aObject2.UriId(); - - CleanupStack::PopAndDestroy(&indexOrder2); - CleanupStack::PopAndDestroy(&indexOrder1); - return compareRes; - } + /* --- NOT SURE IF THIS BEHAVIOR IS REQUIRED --- + // Append remaining elements in order + for ( int i = 0; i < aObject1.DataElementCount(); i++ ) + { + if ( indexOrder.Find(i) == KErrNone && aObject1.Data(i) ) + { + data1 += aObject1.Data(i)->Des(); + data1 += KSpace; + } + } + */ - // The comparison between contacts data is done for the sort order - // fields skipping the ones that are empty - TInt indexCount = indexOrder1.Count(); - TInt idx1 = 0; - TInt idx2 = 0; - while ( compareRes == 0 && idx1 < indexCount && idx2 < indexCount ) + // Data2 + TBuf<255> data2(KNullDesC); + TInt uriId2 = aObject2.UriId(); + cache = (*pcsCache)[uriId2]; + + indexOrder.Reset(); + + // Get the index order based on sort order from the cache + cache->GetIndexOrder(indexOrder); + + // Append sort order elements first + for (int i = 0; i < indexOrder.Count(); i++) { - // Get contact field of 1st contact - TInt object1Idx = indexOrder1[idx1]; - HBufC* strCompare1 = aObject1.Data(object1Idx)->Des().AllocLC(); - TPtr strCompare1Ptr( strCompare1->Des() ); - CPcsAlgorithm2Utils::MyTrim( strCompare1Ptr ); - - // Get contact field of 2nd contact - TInt object2Idx = indexOrder2[idx2]; - HBufC* strCompare2 = aObject2.Data(object2Idx)->Des().AllocLC(); - TPtr strCompare2Ptr( strCompare2->Des() ); - CPcsAlgorithm2Utils::MyTrim( strCompare2Ptr ); - - if ( strCompare1->Length() > 0 && strCompare2->Length() > 0 ) + TInt index = indexOrder[i]; + if (index < aObject2.DataElementCount() && aObject2.Data(index)) { - compareRes = CPcsAlgorithm2Utils::MyCompareC(*strCompare1, *strCompare2); - idx1++; - idx2++; - } - else // Increment only the index of the contact with empty field - { - if ( strCompare1->Length() == 0 ) - idx1++; - if ( strCompare2->Length() == 0 ) - idx2++; - } - - CleanupStack::PopAndDestroy(strCompare2); - CleanupStack::PopAndDestroy(strCompare1); - } + // Trim the unnecessary white spaces/special chars before we compare + TBuf<255> str(KNullDesC); - // We do not return that contacts are equal by SO - if ( compareRes == 0 ) - { - if ( idx1 != idx2 ) - { - // Compare by index position - // If idx1 > idx2 and SO is "FN LN" it means for instance that: - // Contact1=[FN:"", LN:"Smith"], idx1=2 - // Contact2=[FN:"Smith", LN:"Donald"], idx2=1 - // Therefore Contact1="Smith" is < than Contact2="Smith Donald" - // and the return value of this method has to be < 0 (idx2-idx1) + str = aObject2.Data(index)->Des(); + CPcsAlgorithm2Utils::MyTrim(str); - compareRes = idx2 - idx1; - } - else - { - // Compare by URI ID as 1st choice and Contact ID as 2nd choice - - compareRes == ( aObject1.UriId() != aObject2.UriId() ) ? - aObject1.UriId() - aObject2.UriId() : aObject1.Id() - aObject2.Id(); + data2 += str; + data2 += KSpace; } } - CleanupStack::PopAndDestroy(&indexOrder2); - CleanupStack::PopAndDestroy(&indexOrder1); - - return compareRes; - } + /* --- NOT SURE IF THIS BEHAVIOR IS REQUIRED --- + // Append remaining elements in order + for ( int i = 0; i < aObject2.DataElementCount(); i++ ) + { + if ( indexOrder.Find(i) == KErrNone && aObject2.Data(i) ) + { + data2 += aObject2.Data(i)->Des(); + data2 += KSpace; + } + } + */ -// ---------------------------------------------------------------------------- -// CPcsAlgorithm2Utils::CompareExact() -// -// ---------------------------------------------------------------------------- -TBool CPcsAlgorithm2Utils::CompareExact(const TDesC& aFirst, const TDesC& aSecond) - { - return aFirst == aSecond; - } - -// ---------------------------------------------------------------------------- -// CPcsAlgorithm2Utils::CompareLength() -// -// ---------------------------------------------------------------------------- -TInt CPcsAlgorithm2Utils::CompareLength(const CPsQuery& aFirst, const CPsQuery& aSecond) - { - CPsQuery& first = const_cast (aFirst); - CPsQuery& second = const_cast (aSecond); - - return (first.Count() - second.Count()); + indexOrder.Reset(); + data1.TrimAll(); + data2.TrimAll(); + return (CPcsAlgorithm2Utils::MyCompareC(data1, data2)); } // ---------------------------------------------------------------------------- @@ -283,90 +233,5 @@ return ETrue; } -// ---------------------------------------------------------------------------- -// CPcsAlgorithm1Helper::FilterDataFieldsL() -// Constructs a bit pattern using the required/supported data fields -// For example, 6, 4 and 27 are supported fields <-- 00000111 -// 6 and 4 are required fields <-- 00000011 -// Bit pattern returned is 00000011. -// ---------------------------------------------------------------------------- -TUint8 CPcsAlgorithm2Utils::FilterDataFieldsL(const RArray& aRequiredDataFields, - const RArray& aSupportedDataFields) -{ - TUint8 filteredMatch = 0x0; - const TInt supportedDataFieldsCount = aSupportedDataFields.Count(); - const TInt requiredDataFieldsCount = aRequiredDataFields.Count(); - for ( TInt i = 0; i < supportedDataFieldsCount; i++ ) - { - for ( TInt j = 0; j < requiredDataFieldsCount; j++ ) - { - if ( aSupportedDataFields[i] == aRequiredDataFields[j] ) - { - TUint8 val = 1 << i; - filteredMatch |= val; - } - } - } - - return filteredMatch; -} - -// ---------------------------------------------------------------------------- -// CPcsAlgorithm2Utils::AppendMatchToSeqL -// ---------------------------------------------------------------------------- -void CPcsAlgorithm2Utils::AppendMatchToSeqL( - RPointerArray& aMatchSeq, const TDesC& aMatch ) - { - HBufC* seq = aMatch.AllocLC(); - seq->Des().UpperCase(); - TIdentityRelation rule(CompareExact); - if ( aMatchSeq.Find(seq, rule) == KErrNotFound ) - { - aMatchSeq.AppendL(seq); - CleanupStack::Pop( seq ); - } - else - { - CleanupStack::PopAndDestroy( seq ); - } - } - -// ---------------------------------------------------------------------------- -// CPcsAlgorithm2Utils::MatchesOverlap -// Check if two match location items have overlapping indices. -// ---------------------------------------------------------------------------- -TBool CPcsAlgorithm2Utils::MatchesOverlap( const TPsMatchLocation& aFirst, - const TPsMatchLocation& aSecond ) - { - TBool overlap = EFalse; - - if ( aFirst.index == aSecond.index ) - { - overlap = ETrue; - } - else - { - // give arguments alias names where first begins before the second - TInt firstPos( aFirst.index ); - TInt firstLen( aFirst.length ); - TInt secondPos( aSecond.index ); - if ( firstPos > secondPos ) - { - firstPos = aSecond.index; - firstLen = aSecond.length; - secondPos = aFirst.index; - } - - // there is an overlap if the end of the first comes after - // beginning of the second - if ( firstPos + firstLen > secondPos ) - { - overlap = ETrue; - } - } - - return overlap; - } - // End of File