|
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 #ifndef CSEARCHDOCUMENT_H_ |
|
19 #define CSEARCHDOCUMENT_H_ |
|
20 |
|
21 #include "CDocumentField.h" |
|
22 |
|
23 #include <e32base.h> |
|
24 |
|
25 /** |
|
26 * @file |
|
27 * @ingroup Common |
|
28 * @brief Contains CSearchDocument |
|
29 */ |
|
30 /** |
|
31 * @brief Represents an entity in the index database |
|
32 * @ingroup Common |
|
33 * |
|
34 * CSearchDocument represents one entity in index database, e.g. it can appear in search result. |
|
35 * Each document may have multiple fields, which values may or may not be indexed and stored to database. |
|
36 * See CDocumentField for details. |
|
37 * |
|
38 * Link against: CPixSearchClient.lib |
|
39 */ |
|
40 class CSearchDocument : public CBase |
|
41 { |
|
42 public: // Datatypes |
|
43 |
|
44 enum TFilterId |
|
45 { |
|
46 ENoFilter, |
|
47 EFileParser |
|
48 }; |
|
49 |
|
50 /** |
|
51 * The default boost value for documents |
|
52 */ |
|
53 const static TReal32 KDefaultBoost; |
|
54 |
|
55 public: // Constructors and destructor |
|
56 |
|
57 /** |
|
58 * Creates a new CSearchDocument and returns a pointer to it. |
|
59 * @return A pointer to the new CSearchDocument |
|
60 */ |
|
61 IMPORT_C static CSearchDocument* NewL(RReadStream& aReadStream); |
|
62 |
|
63 /** |
|
64 * Creates a new CSearchDocument and returns a pointer to it. |
|
65 * @return A pointer to the new CSearchDocument |
|
66 */ |
|
67 IMPORT_C static CSearchDocument* NewL(const TDesC& aDocumentId, |
|
68 const TDesC& aAppClass, |
|
69 const TDesC& aExcerpt = KNullDesC, |
|
70 const TFilterId aFilterId = ENoFilter ); |
|
71 |
|
72 /** |
|
73 * Creates a new CSearchDocument and returns a pointer to it. |
|
74 * @return A pointer to the new CSearchDocument |
|
75 */ |
|
76 IMPORT_C static CSearchDocument* NewLC(RReadStream& aReadStream); |
|
77 |
|
78 /** |
|
79 * Creates a new CSearchDocument and returns a pointer to it. |
|
80 * @return A pointer to the new CSearchDocument |
|
81 */ |
|
82 IMPORT_C static CSearchDocument* NewLC(const TDesC& aDocumentId, |
|
83 const TDesC& aAppClass, |
|
84 const TDesC& aExcerpt = KNullDesC, |
|
85 const TFilterId aFilterId = ENoFilter ); |
|
86 |
|
87 /** |
|
88 * Destructor. |
|
89 */ |
|
90 IMPORT_C virtual ~CSearchDocument(); |
|
91 |
|
92 public: // New functions |
|
93 |
|
94 /** |
|
95 * Number of bytes occupied by the data represented by this document. |
|
96 * @return The size of the data represented by this document. |
|
97 */ |
|
98 IMPORT_C TInt Size() const; |
|
99 |
|
100 /** |
|
101 * Externalize this document field to a write stream. |
|
102 * @param aWriteStream Write stream for externalization. |
|
103 */ |
|
104 IMPORT_C void ExternalizeL(RWriteStream& aWriteStream) const; |
|
105 |
|
106 /** |
|
107 * Internalize this document from a read stream. |
|
108 * @param aReadStream Read stream for internalization. |
|
109 */ |
|
110 IMPORT_C void InternalizeL(RReadStream& aReadStream); |
|
111 |
|
112 /** |
|
113 * Adds new field to this document. |
|
114 * @param aName Name of the new field. |
|
115 * @param aValue Value of the field. |
|
116 * @param aConfig Storing and indexing configuration of this field. |
|
117 * @return Reference to created field. |
|
118 */ |
|
119 IMPORT_C CDocumentField& AddFieldL(const TDesC& aName, const TDesC& aValue, const TInt aConfig = CDocumentField::KDefaultConfig); |
|
120 |
|
121 /** |
|
122 * TODO |
|
123 */ |
|
124 IMPORT_C TBool RemoveField(const TDesC& aName); |
|
125 |
|
126 /** |
|
127 * Adds excerpt to the document |
|
128 * Overwrites current excerpt |
|
129 * To be used if no exceprt was included on document creation |
|
130 * @param aExcerpt Excerpt text to add to the document. |
|
131 */ |
|
132 IMPORT_C void AddExcerptL(const TDesC& aExcerpt); |
|
133 |
|
134 /** |
|
135 * Find field by name. Returns NULL, if field is not found with given name. |
|
136 * @param aName Name of the field. |
|
137 * @return First field with given name or NULL if no field is found. |
|
138 */ |
|
139 IMPORT_C const CDocumentField* Field(const TDesC& aName) const; |
|
140 |
|
141 /** |
|
142 * Id of this document. |
|
143 * @return Id of this document. |
|
144 */ |
|
145 IMPORT_C const TDesC& Id() const; |
|
146 |
|
147 /** |
|
148 * Application class of this document. |
|
149 * @return Application class of this document. |
|
150 */ |
|
151 IMPORT_C const TDesC& AppClass() const; |
|
152 |
|
153 /** |
|
154 * Excerpt of this document. |
|
155 * @return Excerpt of this document. |
|
156 */ |
|
157 IMPORT_C const TDesC& Excerpt() const; |
|
158 |
|
159 /** |
|
160 * Number of fields in this document. |
|
161 * @return Number of fields in this document. |
|
162 */ |
|
163 IMPORT_C TInt FieldCount() const; |
|
164 |
|
165 /** |
|
166 * Returns a field specified by the index. |
|
167 * Raises panic USER 130 if index is negative or greater than the number of fields currently in document. |
|
168 * @param aIndex Index of a field to be returned. |
|
169 * @return Field pointed by the index. |
|
170 */ |
|
171 IMPORT_C const CDocumentField& Field( const TInt aIndex ) const; |
|
172 |
|
173 /** |
|
174 * Sets the document boost. Documents with high boost value are |
|
175 * ranked higher in the search results. |
|
176 */ |
|
177 IMPORT_C void SetBoost( TReal32 aBoost ); |
|
178 |
|
179 /** |
|
180 * Gets the document boost. Documents with high boost value are |
|
181 * ranked higher in the search results. |
|
182 */ |
|
183 IMPORT_C TReal32 Boost() const; |
|
184 |
|
185 private: // Constructors |
|
186 |
|
187 /** |
|
188 * C++ default constructor |
|
189 */ |
|
190 CSearchDocument(); |
|
191 |
|
192 /** |
|
193 * For documents objects which ID is already known (f.e. Document objects to be created from Hits) |
|
194 */ |
|
195 void ConstructL(const TDesC& aDocumentId, |
|
196 const TDesC& aAppClass, |
|
197 const TDesC& aExcerpt, |
|
198 const TFilterId aFilterId ); |
|
199 |
|
200 /** |
|
201 * Symbian second phase constructor. |
|
202 */ |
|
203 void ConstructL(RReadStream& aReadStream); |
|
204 |
|
205 private: // Data |
|
206 |
|
207 /** |
|
208 * Array for the fields of this document. |
|
209 */ |
|
210 RPointerArray<CDocumentField> iFields; |
|
211 |
|
212 TReal32 iBoost; |
|
213 |
|
214 }; |
|
215 |
|
216 #endif /*CSEARCHDOCUMENT_H_*/ |