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 TERMVECTORMAPPER_H
8 #define TERMVECTORMAPPER_H
9 
10 #include "LuceneObject.h"
11 
12 namespace Lucene {
13 
14 /// The TermVectorMapper can be used to map Term Vectors into your own structure instead of the parallel
15 /// array structure used by {@link IndexReader#getTermFreqVector(int,String)}.
16 ///
17 /// It is up to the implementation to make sure it is thread-safe.
18 class LPPAPI TermVectorMapper : public LuceneObject {
19 public:
20     /// @param ignoringPositions true if this mapper should tell Lucene to ignore positions even if
21     /// they are stored.
22     /// @param ignoringOffsets similar to ignoringPositions
23     TermVectorMapper(bool ignoringPositions = false, bool ignoringOffsets = false);
24 
25     virtual ~TermVectorMapper();
26 
27     LUCENE_CLASS(TermVectorMapper);
28 
29 protected:
30     bool ignoringPositions;
31     bool ignoringOffsets;
32 
33 public:
34     /// Tell the mapper what to expect in regards to field, number of terms, offset and position storage.
35     /// This method will be called once before retrieving the vector for a field.
36     ///
37     /// This method will be called before {@link #map(String,int,TermVectorOffsetInfo[],int[])}.
38     /// @param field The field the vector is for
39     /// @param numTerms The number of terms that need to be mapped
40     /// @param storeOffsets true if the mapper should expect offset information
41     /// @param storePositions true if the mapper should expect positions info
42     virtual void setExpectations(const String& field, int32_t numTerms, bool storeOffsets, bool storePositions) = 0;
43 
44     /// Map the Term Vector information into your own structure
45     /// @param term The term to add to the vector
46     /// @param frequency The frequency of the term in the document
47     /// @param offsets null if the offset is not specified, otherwise the offset into the field of the term
48     /// @param positions null if the position is not specified, otherwise the position in the field of the term
49     virtual void map(const String& term, int32_t frequency, Collection<TermVectorOffsetInfoPtr> offsets, Collection<int32_t> positions) = 0;
50 
51     /// Indicate to Lucene that even if there are positions stored, this mapper is not interested in them and
52     /// they can be skipped over.  Derived classes should set this to true if they want to ignore positions.
53     /// The default is false, meaning positions will be loaded if they are stored.
54     virtual bool isIgnoringPositions();
55 
56     /// @see #isIgnoringPositions() Same principal as {@link #isIgnoringPositions()}, but applied to offsets.
57     virtual bool isIgnoringOffsets();
58 
59     /// Passes down the index of the document whose term vector is currently being mapped, once for each top
60     /// level call to a term vector reader.
61     ///
62     /// Default implementation IGNORES the document number.  Override if your implementation needs the document
63     /// number.
64     ///
65     /// NOTE: Document numbers are internal to Lucene and subject to change depending on indexing operations.
66     ///
67     /// @param documentNumber index of document currently being mapped
68     virtual void setDocumentNumber(int32_t documentNumber);
69 };
70 
71 }
72 
73 #endif
74