|
1 /* |
|
2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 #include "CSearchDocument.h" |
|
19 #include "CDocumentField.h" |
|
20 #include "HarvesterServerLogger.h" |
|
21 |
|
22 #include "indevicecfg.h" |
|
23 |
|
24 /* |
|
25 * This is exactly the same as in CLucene |
|
26 */ |
|
27 const TReal32 CSearchDocument::KDefaultBoost = 1.0f; |
|
28 |
|
29 EXPORT_C CSearchDocument* CSearchDocument::NewL(RReadStream& aReadStream) |
|
30 { |
|
31 CSearchDocument* self = CSearchDocument::NewLC(aReadStream); |
|
32 CleanupStack::Pop(self); |
|
33 return self; |
|
34 } |
|
35 |
|
36 EXPORT_C CSearchDocument* CSearchDocument::NewL(const TDesC& aDocumentId, |
|
37 const TDesC& aAppClass, |
|
38 const TDesC& aExcerpt, |
|
39 const TFilterId aFilterId) |
|
40 { |
|
41 CSearchDocument* self = CSearchDocument::NewLC(aDocumentId, aAppClass, aExcerpt, aFilterId); |
|
42 CleanupStack::Pop(self); |
|
43 return self; |
|
44 } |
|
45 |
|
46 EXPORT_C CSearchDocument* CSearchDocument::NewLC(RReadStream& aReadStream) |
|
47 { |
|
48 CSearchDocument* self = new (ELeave)CSearchDocument(); |
|
49 CleanupStack::PushL(self); |
|
50 self->ConstructL(aReadStream); |
|
51 return self; |
|
52 } |
|
53 |
|
54 EXPORT_C CSearchDocument* CSearchDocument::NewLC(const TDesC& aDocumentId, |
|
55 const TDesC& aAppClass, |
|
56 const TDesC& aExcerpt, |
|
57 const TFilterId aFilterId) |
|
58 { |
|
59 CSearchDocument* self = new (ELeave)CSearchDocument(); |
|
60 CleanupStack::PushL(self); |
|
61 self->ConstructL(aDocumentId, aAppClass, aExcerpt, aFilterId); |
|
62 return self; |
|
63 } |
|
64 |
|
65 CSearchDocument::CSearchDocument() |
|
66 : iFields(), |
|
67 iBoost( KDefaultBoost ) |
|
68 { |
|
69 } |
|
70 |
|
71 EXPORT_C CSearchDocument::~CSearchDocument() |
|
72 { |
|
73 iFields.ResetAndDestroy(); |
|
74 iFields.Close(); |
|
75 } |
|
76 |
|
77 void CSearchDocument::ConstructL(RReadStream& aReadStream) |
|
78 { |
|
79 InternalizeL(aReadStream); |
|
80 } |
|
81 |
|
82 void CSearchDocument::ConstructL(const TDesC& aDocumentId, |
|
83 const TDesC& aAppClass, |
|
84 const TDesC& aExcerpt, |
|
85 const TFilterId aFilterId) |
|
86 { |
|
87 // creating unique string identifier: |
|
88 AddFieldL( _L( CPIX_DOCUID_FIELD ), aDocumentId, CDocumentField::EStoreYes | CDocumentField::EIndexUnTokenized ); |
|
89 if ( KNullDesC() != aAppClass ) |
|
90 { |
|
91 AddFieldL( _L( CPIX_APPCLASS_FIELD ), aAppClass, CDocumentField::EStoreYes | CDocumentField::EIndexTokenized ); |
|
92 } |
|
93 if ( KNullDesC() != aExcerpt ) |
|
94 { |
|
95 AddFieldL( _L( CPIX_EXCERPT_FIELD ), aExcerpt, CDocumentField::EStoreYes | CDocumentField::EIndexNo ); |
|
96 } |
|
97 |
|
98 switch (aFilterId) |
|
99 { |
|
100 case ENoFilter: |
|
101 { |
|
102 // Nothing to do |
|
103 break; |
|
104 } |
|
105 case EFileParser: |
|
106 { |
|
107 // TODO: These must match to definitions in cpixdoc.cpp |
|
108 _LIT(KFilterFieldName, CPIX_FILTERID_FIELD); |
|
109 _LIT(KFilterFieldValue, "FileParser"); |
|
110 AddFieldL(KFilterFieldName, KFilterFieldValue, CDocumentField::EStoreYes | CDocumentField::EIndexNo ); |
|
111 break; |
|
112 } |
|
113 default: |
|
114 User::Leave(KErrArgument); |
|
115 } |
|
116 } |
|
117 |
|
118 EXPORT_C TInt CSearchDocument::Size() const |
|
119 { |
|
120 TInt r = sizeof(iFields.Count()); |
|
121 |
|
122 r += sizeof(TReal); |
|
123 |
|
124 for ( TInt i = 0; i < iFields.Count(); ++i ) |
|
125 { |
|
126 r += iFields[i]->Size(); |
|
127 } |
|
128 |
|
129 return r; |
|
130 } |
|
131 |
|
132 EXPORT_C void CSearchDocument::ExternalizeL(RWriteStream& aWriteStream) const |
|
133 { |
|
134 aWriteStream.WriteReal32L( iBoost ); |
|
135 |
|
136 aWriteStream.WriteInt32L(iFields.Count()); |
|
137 for (TInt i=0; i<iFields.Count(); i++) |
|
138 { |
|
139 iFields[i]->ExternalizeL(aWriteStream); |
|
140 } |
|
141 } |
|
142 |
|
143 EXPORT_C void CSearchDocument::InternalizeL(RReadStream& aReadStream) |
|
144 { |
|
145 iBoost = aReadStream.ReadReal32L(); |
|
146 |
|
147 TInt32 count = aReadStream.ReadInt32L(); |
|
148 for (TInt i=0; i<count; i++) |
|
149 { |
|
150 CDocumentField* new_field = CDocumentField::NewLC(aReadStream); |
|
151 iFields.AppendL(new_field); |
|
152 CleanupStack::Pop(new_field); |
|
153 } |
|
154 } |
|
155 |
|
156 EXPORT_C CDocumentField& CSearchDocument::AddFieldL(const TDesC& aName, const TDesC& aStringValue, TInt aConfig) |
|
157 { |
|
158 RemoveField( aName ); |
|
159 |
|
160 CDocumentField* new_field = CDocumentField::NewLC(aName, aStringValue, aConfig); |
|
161 iFields.AppendL(new_field); |
|
162 CleanupStack::Pop(new_field); |
|
163 return *new_field; |
|
164 } |
|
165 |
|
166 EXPORT_C TBool CSearchDocument::RemoveField(const TDesC& aName) |
|
167 { |
|
168 for ( TInt i = 0; i < iFields.Count(); ++i ) |
|
169 { |
|
170 if ( aName == iFields[i]->Name() ) |
|
171 { |
|
172 delete iFields[i]; |
|
173 iFields.Remove(i); |
|
174 return true; |
|
175 } |
|
176 } |
|
177 return false; |
|
178 } |
|
179 |
|
180 EXPORT_C void CSearchDocument::AddExcerptL(const TDesC& aExcerpt) |
|
181 { |
|
182 AddFieldL( _L( CPIX_EXCERPT_FIELD ), aExcerpt, CDocumentField::EStoreYes | CDocumentField::EIndexNo ); |
|
183 } |
|
184 |
|
185 EXPORT_C const CDocumentField* CSearchDocument::Field(const TDesC& aName) const |
|
186 { |
|
187 for ( TInt i = 0; i < iFields.Count(); ++i ) |
|
188 { |
|
189 if ( aName == iFields[i]->Name() ) |
|
190 { |
|
191 return iFields[i]; |
|
192 } |
|
193 } |
|
194 |
|
195 return NULL; |
|
196 } |
|
197 |
|
198 EXPORT_C TInt CSearchDocument::FieldCount() const |
|
199 { |
|
200 return iFields.Count(); |
|
201 } |
|
202 |
|
203 EXPORT_C const CDocumentField& CSearchDocument::Field( const TInt aIndex ) const |
|
204 { |
|
205 return *iFields[ aIndex ]; |
|
206 } |
|
207 |
|
208 EXPORT_C const TDesC& CSearchDocument::Id() const |
|
209 { |
|
210 const CDocumentField* field = Field( _L( CPIX_DOCUID_FIELD ) ); |
|
211 if ( field ) |
|
212 { |
|
213 return field->Value(); |
|
214 } |
|
215 return KNullDesC(); |
|
216 } |
|
217 |
|
218 EXPORT_C const TDesC& CSearchDocument::AppClass() const |
|
219 { |
|
220 const CDocumentField* field = Field( _L( CPIX_APPCLASS_FIELD ) ); |
|
221 if ( field ) |
|
222 { |
|
223 return field->Value(); |
|
224 } |
|
225 return KNullDesC(); |
|
226 } |
|
227 |
|
228 EXPORT_C const TDesC& CSearchDocument::Excerpt() const |
|
229 { |
|
230 const CDocumentField* field = Field( _L( CPIX_EXCERPT_FIELD ) ); |
|
231 if ( field ) |
|
232 { |
|
233 return field->Value(); |
|
234 } |
|
235 return KNullDesC(); |
|
236 } |
|
237 |
|
238 EXPORT_C void CSearchDocument::SetBoost( TReal32 aBoost ) |
|
239 { |
|
240 iBoost = aBoost; |
|
241 } |
|
242 |
|
243 |
|
244 EXPORT_C TReal32 CSearchDocument::Boost() const |
|
245 { |
|
246 return iBoost; |
|
247 } |
|
248 |