1 | /*------------------------------------------------------------------------------ |
2 | * Copyright (C) 2003-2006 Ben van Klinken and the CLucene Team |
3 | * |
4 | * Distributable under the terms of either the Apache License (Version 2.0) or |
5 | * the GNU Lesser General Public License, as specified in the COPYING file. |
6 | ------------------------------------------------------------------------------*/ |
7 | #ifndef _lucene_index_MultiReader |
8 | #define _lucene_index_MultiReader |
9 | |
10 | |
11 | //#include "SegmentHeader.h" |
12 | #include "IndexReader.h" |
13 | CL_CLASS_DEF(document,Document) |
14 | //#include "Terms.h" |
15 | //#include "SegmentMergeQueue.h" |
16 | |
17 | CL_NS_DEF(index) |
18 | |
19 | /** An IndexReader which reads multiple indexes, appending their content. |
20 | */ |
21 | class CLUCENE_EXPORT MultiReader:public IndexReader{ |
22 | private: |
23 | class Internal; |
24 | Internal* _internal; |
25 | int32_t readerIndex(const int32_t n) const; |
26 | bool hasNorms(const TCHAR* field); |
27 | uint8_t* fakeNorms(); |
28 | |
29 | void init(const CL_NS(util)::ArrayBase<IndexReader*>* subReaders, bool closeSubReaders); |
30 | protected: |
31 | CL_NS(util)::ArrayBase<IndexReader*>* subReaders; |
32 | int32_t* starts; // 1st docno for each segment |
33 | |
34 | void doSetNorm(int32_t n, const TCHAR* field, uint8_t value); |
35 | void doUndeleteAll(); |
36 | void doCommit(); |
37 | void doClose(); |
38 | void doDelete(const int32_t n); |
39 | public: |
40 | /** |
41 | * <p>Construct a MultiReader aggregating the named set of (sub)readers. |
42 | * Directory locking for delete, undeleteAll, and setNorm operations is |
43 | * left to the subreaders. </p> |
44 | * @param subReaders set of (sub)readers |
45 | * @param closeSubReaders The subReaders (IndexReader instances) are deleted if true |
46 | * @throws IOException |
47 | * @memory The subReaders array itself belongs to the caller |
48 | */ |
49 | MultiReader(const CL_NS(util)::ArrayBase<IndexReader*>* subReaders, bool closeSubReaders=true); |
50 | |
51 | ~MultiReader(); |
52 | |
53 | |
54 | /** |
55 | * Tries to reopen the subreaders. |
56 | * <br> |
57 | * If one or more subreaders could be re-opened (i. e. subReader.reopen() |
58 | * returned a new instance != subReader), then a new MultiReader instance |
59 | * is returned, otherwise this instance is returned. |
60 | * <p> |
61 | * A re-opened instance might share one or more subreaders with the old |
62 | * instance. Index modification operations result in undefined behavior |
63 | * when performed before the old instance is closed. |
64 | * (see {@link IndexReader#reopen()}). |
65 | * <p> |
66 | * If subreaders are shared, then the reference count of those |
67 | * readers is increased to ensure that the subreaders remain open |
68 | * until the last referring reader is closed. |
69 | * |
70 | * @throws CorruptIndexException if the index is corrupt |
71 | * @throws IOException if there is a low-level IO error |
72 | */ |
73 | IndexReader* reopen(); |
74 | |
75 | TermFreqVector* getTermFreqVector(int32_t n, const TCHAR* field=NULL); |
76 | |
77 | void getTermFreqVector(int32_t docNumber, const TCHAR* field, TermVectorMapper* mapper); |
78 | void getTermFreqVector(int32_t docNumber, TermVectorMapper* mapper); |
79 | |
80 | /** Return an array of term frequency vectors for the specified document. |
81 | * The array contains a vector for each vectorized field in the document. |
82 | * Each vector vector contains term numbers and frequencies for all terms |
83 | * in a given vectorized field. |
84 | * If no such fields existed, the method returns null. |
85 | */ |
86 | CL_NS(util)::ArrayBase<TermFreqVector*>* getTermFreqVectors(int32_t n); |
87 | |
88 | bool isOptimized(); |
89 | |
90 | int32_t numDocs(); |
91 | int32_t maxDoc() const; |
92 | bool document(int32_t n, CL_NS(document)::Document& doc, const CL_NS(document)::FieldSelector* fieldSelector); |
93 | bool isDeleted(const int32_t n); |
94 | bool hasDeletions() const; |
95 | uint8_t* norms(const TCHAR* field); |
96 | void norms(const TCHAR* field, uint8_t* result); |
97 | TermEnum* terms(); |
98 | TermEnum* terms(const Term* term); |
99 | |
100 | //Returns the document frequency of the current term in the set |
101 | int32_t docFreq(const Term* t=NULL); |
102 | TermDocs* termDocs(); |
103 | TermPositions* termPositions(); |
104 | |
105 | /** |
106 | * @see IndexReader#getFieldNames(IndexReader.FieldOption fldOption) |
107 | */ |
108 | void getFieldNames(FieldOption fldOption, StringArrayWithDeletor& retarray); |
109 | |
110 | |
111 | /** |
112 | * Checks recursively if all subreaders are up to date. |
113 | */ |
114 | bool isCurrent(); |
115 | |
116 | /** Not implemented. |
117 | * @throws UnsupportedOperationException |
118 | */ |
119 | int64_t getVersion(); |
120 | |
121 | const CL_NS(util)::ArrayBase<IndexReader*>* getSubReaders() const; |
122 | |
123 | static const char* getClassName(); |
124 | const char* getObjectName() const; |
125 | }; |
126 | |
127 | |
128 | CL_NS_END |
129 | #endif |
130 | |