91 // the field name is not checked, all _appclass, |
95 // the field name is not checked, all _appclass, |
92 // _excerpt etc. fields will be overwritten. |
96 // _excerpt etc. fields will be overwritten. |
93 document->AddFieldL(namePtr, stringvalue); |
97 document->AddFieldL(namePtr, stringvalue); |
94 } |
98 } |
95 |
99 |
96 CleanupStack::PopAndDestroy(docFieldEnum); |
100 CleanupStack::PopAndDestroy(docFieldEnum); |
97 |
|
98 CleanupStack::Pop(document); |
101 CleanupStack::Pop(document); |
99 |
102 delete aDocument; |
100 return document; |
103 return document; |
101 } |
104 } |
|
105 |
|
106 RPointerArray<CSearchDocument> CCPixAbstractSearcher::ConvertBatchDocumentL( cpix_Document** aDocument, TInt aCount ) |
|
107 { |
|
108 // Read first the system fields that are passed as constructor parameters |
|
109 // |
|
110 RPointerArray<CSearchDocument> docArray; |
|
111 docSizeArray.Reset(); |
|
112 //docArray.Reset(); // delete each element |
|
113 |
|
114 for( TInt i= 0;i< aCount;i++ ) |
|
115 { |
|
116 cpix_Document* nextDocument = aDocument[i]; |
|
117 |
|
118 if( nextDocument->ptr_ ) |
|
119 { |
|
120 const wchar_t* documentId = cpix_Document_getFieldValue( nextDocument, LCPIX_DOCUID_FIELD); |
|
121 SearchServerHelper::CheckCpixErrorL(nextDocument, KErrDatabaseQueryFailed); |
|
122 |
|
123 TPtrC documentIdPtr(KNullDesC); |
|
124 if (documentId) |
|
125 documentIdPtr.Set(reinterpret_cast<const TUint16*>(documentId)); |
|
126 |
|
127 const wchar_t* documentAppClass = cpix_Document_getFieldValue(nextDocument, LCPIX_APPCLASS_FIELD); |
|
128 SearchServerHelper::CheckCpixErrorL(nextDocument, KErrDatabaseQueryFailed); |
|
129 |
|
130 TPtrC documentAppClassPtr(KNullDesC); |
|
131 if (documentAppClass) |
|
132 documentAppClassPtr.Set(reinterpret_cast<const TUint16*>(documentAppClass)); |
|
133 |
|
134 const wchar_t* documentExcerpt = cpix_Document_getFieldValue(nextDocument, LCPIX_EXCERPT_FIELD); |
|
135 SearchServerHelper::CheckCpixErrorL(nextDocument, KErrDatabaseQueryFailed); |
|
136 |
|
137 TPtrC documentExcerptPtr(KNullDesC); |
|
138 if (documentExcerpt) |
|
139 documentExcerptPtr.Set(reinterpret_cast<const TUint16*>(documentExcerpt)); |
|
140 |
|
141 // Setup the document |
|
142 // |
|
143 |
|
144 CSearchDocument* document = CSearchDocument::NewLC(documentIdPtr, documentAppClassPtr, documentExcerptPtr); |
|
145 |
|
146 // Enumerate the field of cpix_Document and add each of them |
|
147 // into the CSearchDocument object. |
|
148 // |
|
149 |
|
150 cpix_DocFieldEnum* docFieldEnum = cpix_Document_fields(nextDocument); |
|
151 SearchServerHelper::CheckCpixErrorL(nextDocument, KErrDocumentAccessFailed); |
|
152 |
|
153 CleanupStack::PushL( TCleanupItem(CpixDocFieldEnumDestroyer, docFieldEnum) ); |
|
154 |
|
155 cpix_Field field; |
|
156 while (cpix_DocFieldEnum_hasMore(docFieldEnum)) |
|
157 { |
|
158 cpix_DocFieldEnum_next(docFieldEnum, &field); |
|
159 SearchServerHelper::CheckCpixErrorL(docFieldEnum, KErrDatabaseQueryFailed); |
|
160 |
|
161 const wchar_t* name = cpix_Field_name(&field); |
|
162 SearchServerHelper::CheckCpixErrorL(&field, KErrDatabaseQueryFailed); |
|
163 |
|
164 TPtrC namePtr( reinterpret_cast<const TUint16*>( name ) ); |
|
165 if ( namePtr == TPtrC( (TUint16*)LCPIX_DOCUID_FIELD ) |
|
166 || namePtr == TPtrC( (TUint16*)LCPIX_APPCLASS_FIELD ) |
|
167 || namePtr == TPtrC( (TUint16*)LCPIX_EXCERPT_FIELD ) ) |
|
168 { |
|
169 continue; // These fields have already been added |
|
170 } |
|
171 |
|
172 const wchar_t* value = cpix_Field_stringValue(&field); |
|
173 SearchServerHelper::CheckCpixErrorL(&field, KErrDatabaseQueryFailed); |
|
174 |
|
175 TPtrC stringvalue( reinterpret_cast<const TUint16*>( value ) ); |
|
176 |
|
177 // NOTE: Also system fields will be iterated. Because |
|
178 // the field name is not checked, all _appclass, |
|
179 // _excerpt etc. fields will be overwritten. |
|
180 document->AddFieldL(namePtr, stringvalue); |
|
181 } |
|
182 CleanupStack::PopAndDestroy(docFieldEnum); |
|
183 CleanupStack::Pop(document); |
|
184 docSizeArray.AppendL( document->Size()); |
|
185 docArray.AppendL( document ); |
|
186 delete nextDocument; |
|
187 nextDocument = NULL; |
|
188 } |
|
189 else break; |
|
190 } |
|
191 delete aDocument; |
|
192 aDocument = NULL; |
|
193 return docArray; |
|
194 } |