|
1 /* |
|
2 * CCPixAbstractSearcher.cpp |
|
3 * |
|
4 * Created on: Oct 8, 2009 |
|
5 * Author: admin |
|
6 */ |
|
7 #include "CCpixAbstractSearcher.h" |
|
8 |
|
9 #include "Common.h" |
|
10 #include "SearchServerHelper.h" |
|
11 #include "CSearchDocument.h" |
|
12 |
|
13 CCPixAbstractSearcher::~CCPixAbstractSearcher() {} |
|
14 |
|
15 |
|
16 namespace { |
|
17 |
|
18 /** |
|
19 * cpix_DocFieldEnum destroyer for TCleanupItem |
|
20 * @param aCpixDocFieldEnum CPix document |
|
21 */ |
|
22 void CpixDocFieldEnumDestroyer(TAny* aCpixDocFieldEnum) |
|
23 { |
|
24 cpix_DocFieldEnum_destroy( static_cast<cpix_DocFieldEnum*>( aCpixDocFieldEnum ) ); |
|
25 } |
|
26 |
|
27 } // namespace |
|
28 |
|
29 CSearchDocument* CCPixAbstractSearcher::ConvertDocumentL( cpix_Document* aDocument ) |
|
30 { |
|
31 // Read first the system fields that are passed as constructor parameters |
|
32 // |
|
33 const wchar_t* documentId = cpix_Document_getFieldValue( aDocument, LCPIX_DOCUID_FIELD); |
|
34 SearchServerHelper::CheckCpixErrorL(aDocument, KErrDatabaseQueryFailed); |
|
35 |
|
36 TPtrC documentIdPtr(KNullDesC); |
|
37 if (documentId) |
|
38 documentIdPtr.Set(reinterpret_cast<const TUint16*>(documentId)); |
|
39 |
|
40 const wchar_t* documentAppClass = cpix_Document_getFieldValue(aDocument, LCPIX_APPCLASS_FIELD); |
|
41 SearchServerHelper::CheckCpixErrorL(aDocument, KErrDatabaseQueryFailed); |
|
42 |
|
43 TPtrC documentAppClassPtr(KNullDesC); |
|
44 if (documentAppClass) |
|
45 documentAppClassPtr.Set(reinterpret_cast<const TUint16*>(documentAppClass)); |
|
46 |
|
47 const wchar_t* documentExcerpt = cpix_Document_getFieldValue(aDocument, LCPIX_EXCERPT_FIELD); |
|
48 SearchServerHelper::CheckCpixErrorL(aDocument, KErrDatabaseQueryFailed); |
|
49 |
|
50 TPtrC documentExcerptPtr(KNullDesC); |
|
51 if (documentExcerpt) |
|
52 documentExcerptPtr.Set(reinterpret_cast<const TUint16*>(documentExcerpt)); |
|
53 |
|
54 // Setup the document |
|
55 // |
|
56 |
|
57 CSearchDocument* document = CSearchDocument::NewLC(documentIdPtr, documentAppClassPtr, documentExcerptPtr); |
|
58 |
|
59 // Enumerate the field of cpix_Document and add each of them |
|
60 // into the CSearchDocument object. |
|
61 // |
|
62 |
|
63 cpix_DocFieldEnum* docFieldEnum = cpix_Document_fields(aDocument); |
|
64 SearchServerHelper::CheckCpixErrorL(aDocument, KErrDocumentAccessFailed); |
|
65 |
|
66 CleanupStack::PushL( TCleanupItem(CpixDocFieldEnumDestroyer, docFieldEnum) ); |
|
67 |
|
68 cpix_Field field; |
|
69 while (cpix_DocFieldEnum_hasMore(docFieldEnum)) |
|
70 { |
|
71 cpix_DocFieldEnum_next(docFieldEnum, &field); |
|
72 SearchServerHelper::CheckCpixErrorL(docFieldEnum, KErrDatabaseQueryFailed); |
|
73 |
|
74 const wchar_t* name = cpix_Field_name(&field); |
|
75 SearchServerHelper::CheckCpixErrorL(&field, KErrDatabaseQueryFailed); |
|
76 |
|
77 TPtrC namePtr( reinterpret_cast<const TUint16*>( name ) ); |
|
78 if ( namePtr == TPtrC( (TUint16*)LCPIX_DOCUID_FIELD ) |
|
79 || namePtr == TPtrC( (TUint16*)LCPIX_APPCLASS_FIELD ) |
|
80 || namePtr == TPtrC( (TUint16*)LCPIX_EXCERPT_FIELD ) ) |
|
81 { |
|
82 continue; // These fields have already been added |
|
83 } |
|
84 |
|
85 const wchar_t* value = cpix_Field_stringValue(&field); |
|
86 SearchServerHelper::CheckCpixErrorL(&field, KErrDatabaseQueryFailed); |
|
87 |
|
88 TPtrC stringvalue( reinterpret_cast<const TUint16*>( value ) ); |
|
89 |
|
90 // NOTE: Also system fields will be iterated. Because |
|
91 // the field name is not checked, all _appclass, |
|
92 // _excerpt etc. fields will be overwritten. |
|
93 document->AddFieldL(namePtr, stringvalue); |
|
94 } |
|
95 |
|
96 CleanupStack::PopAndDestroy(docFieldEnum); |
|
97 |
|
98 CleanupStack::Pop(document); |
|
99 |
|
100 return document; |
|
101 } |