1 /////////////////////////////////////////////////////////////////////////////
2 // Copyright (c) 2009-2014 Alan Wright. All rights reserved.
3 // Distributable under the terms of either the Apache License (Version 2.0)
4 // or the GNU Lesser General Public License.
5 /////////////////////////////////////////////////////////////////////////////
6 
7 #ifndef DOCHELPER_H
8 #define DOCHELPER_H
9 
10 #include "test_lucene.h"
11 
12 namespace Lucene {
13 
14 class DocHelper {
15 public:
16     DocHelper();
17     virtual ~DocHelper();
18 
19 public:
20     static const wchar_t* FIELD_1_TEXT;
21     static const wchar_t* TEXT_FIELD_1_KEY;
22     static FieldPtr textField1;
23 
24     static const wchar_t* FIELD_2_TEXT;
25     static const int32_t FIELD_2_FREQS[];
26     static const wchar_t* TEXT_FIELD_2_KEY;
27     static FieldPtr textField2;
28 
29     static const wchar_t* FIELD_3_TEXT;
30     static const wchar_t* TEXT_FIELD_3_KEY;
31     static FieldPtr textField3;
32 
33     static const wchar_t* KEYWORD_TEXT;
34     static const wchar_t* KEYWORD_FIELD_KEY;
35     static FieldPtr keyField;
36 
37     static const wchar_t* NO_NORMS_TEXT;
38     static const wchar_t* NO_NORMS_KEY;
39     static FieldPtr noNormsField;
40 
41     static const wchar_t* NO_TF_TEXT;
42     static const wchar_t* NO_TF_KEY;
43     static FieldPtr noTFField;
44 
45     static const wchar_t* UNINDEXED_FIELD_TEXT;
46     static const wchar_t* UNINDEXED_FIELD_KEY;
47     static FieldPtr unIndField;
48 
49     static const wchar_t* UNSTORED_1_FIELD_TEXT;
50     static const wchar_t* UNSTORED_FIELD_1_KEY;
51     static FieldPtr unStoredField1;
52 
53     static const wchar_t* UNSTORED_2_FIELD_TEXT;
54     static const wchar_t* UNSTORED_FIELD_2_KEY;
55     static FieldPtr unStoredField2;
56 
57     static const wchar_t* LAZY_FIELD_BINARY_KEY;
58     static ByteArray LAZY_FIELD_BINARY_BYTES;
59     static FieldPtr lazyFieldBinary;
60 
61     static const wchar_t* LAZY_FIELD_KEY;
62     static const wchar_t* LAZY_FIELD_TEXT;
63     static FieldPtr lazyField;
64 
65     static const wchar_t* LARGE_LAZY_FIELD_KEY;
66     static String LARGE_LAZY_FIELD_TEXT;
67     static FieldPtr largeLazyField;
68 
69     static const uint8_t _FIELD_UTF1_TEXT[];
70     static const String FIELD_UTF1_TEXT;
71     static const wchar_t* TEXT_FIELD_UTF1_KEY;
72     static FieldPtr textUtfField1;
73 
74     static const uint8_t _FIELD_UTF2_TEXT[];
75     static const String FIELD_UTF2_TEXT;
76     static const int32_t FIELD_UTF2_FREQS[];
77     static const wchar_t* TEXT_FIELD_UTF2_KEY;
78     static FieldPtr textUtfField2;
79 
80     static MapStringString nameValues;
81 
82     static Collection<FieldPtr> fields;
83     static MapStringField all;
84     static MapStringField indexed;
85     static MapStringField stored;
86     static MapStringField unstored;
87     static MapStringField unindexed;
88     static MapStringField termvector;
89     static MapStringField notermvector;
90     static MapStringField lazy;
91     static MapStringField noNorms;
92     static MapStringField noTf;
93 
94 public:
95     /// Adds the fields above to a document
96     void setupDoc(const DocumentPtr& doc);
97 
98     /// Writes the document to the directory using a segment named "test"; returns the SegmentInfo describing the new segment
99     SegmentInfoPtr writeDoc(const DirectoryPtr& dir, const DocumentPtr& doc);
100 
101     /// Writes the document to the directory using the analyzer and the similarity score; returns the SegmentInfo describing the new segment
102     SegmentInfoPtr writeDoc(const DirectoryPtr& dir, const AnalyzerPtr& analyzer, const SimilarityPtr& similarity, const DocumentPtr& doc);
103 
104     int32_t numFields(const DocumentPtr& doc);
105 
106 protected:
107     /// One-time setup to initialise static members
108     void setup();
109 };
110 
111 }
112 
113 #endif
114