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 SORTEDTERMVECTORMAPPER_H
8 #define SORTEDTERMVECTORMAPPER_H
9 
10 #include <boost/function.hpp>
11 #include "TermVectorMapper.h"
12 
13 namespace Lucene {
14 
15 /// Store a sorted collection of {@link TermVectorEntry}s.  Collects all term information into a single,
16 /// sorted set.
17 ///
18 /// NOTE: This Mapper ignores all Field information for the Document.  This means that if you are using offset/
19 /// positions you will not know what Fields they correlate with.
20 ///
21 /// This is not thread-safe
22 class LPPAPI SortedTermVectorMapper : public TermVectorMapper {
23 public:
24     /// @param comparator A Comparator for sorting {@link TermVectorEntry}s
25     SortedTermVectorMapper(TermVectorEntryComparator comparator);
26 
27     SortedTermVectorMapper(bool ignoringPositions, bool ignoringOffsets, TermVectorEntryComparator comparator);
28 
29     virtual ~SortedTermVectorMapper();
30 
31     LUCENE_CLASS(SortedTermVectorMapper);
32 
33 protected:
34     Collection<TermVectorEntryPtr> currentSet;
35     MapStringTermVectorEntry termToTVE;
36     bool storeOffsets;
37     bool storePositions;
38     TermVectorEntryComparator comparator;
39 
40 public:
41     static const wchar_t* ALL;
42 
43 public:
44     /// Map the Term Vector information into your own structure
45     virtual void map(const String& term, int32_t frequency, Collection<TermVectorOffsetInfoPtr> offsets, Collection<int32_t> positions);
46 
47     /// Tell the mapper what to expect in regards to field, number of terms, offset and position storage.
48     virtual void setExpectations(const String& field, int32_t numTerms, bool storeOffsets, bool storePositions);
49 
50     /// The TermVectorEntrySet.  A SortedSet of {@link TermVectorEntry} objects.  Sort is by the comparator passed
51     /// into the constructor.
52     ///
53     /// This set will be empty until after the mapping process takes place.
54     ///
55     /// @return The sorted set of {@link TermVectorEntry}.
56     Collection<TermVectorEntryPtr> getTermVectorEntrySet();
57 };
58 
59 }
60 
61 #endif
62