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