2 using Lucene
.Net
.Store
;
4 namespace Lucene
.Net
.Index
6 /* ====================================================================
7 * The Apache Software License, Version 1.1
9 * Copyright (c) 2001 The Apache Software Foundation. All rights
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
16 * 1. Redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer.
19 * 2. Redistributions in binary form must reproduce the above copyright
20 * notice, this list of conditions and the following disclaimer in
21 * the documentation and/or other materials provided with the
24 * 3. The end-user documentation included with the redistribution,
25 * if any, must include the following acknowledgment:
26 * "This product includes software developed by the
27 * Apache Software Foundation (http://www.apache.org/)."
28 * Alternately, this acknowledgment may appear in the software itself,
29 * if and wherever such third-party acknowledgments normally appear.
31 * 4. The names "Apache" and "Apache Software Foundation" and
32 * "Apache Lucene" must not be used to endorse or promote products
33 * derived from this software without prior written permission. For
34 * written permission, please contact apache@apache.org.
36 * 5. Products derived from this software may not be called "Apache",
37 * "Apache Lucene", nor may "Apache" appear in their name, without
38 * prior written permission of the Apache Software Foundation.
40 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
41 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
42 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
43 * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
44 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
45 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
46 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
47 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
48 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
49 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
50 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
52 * ====================================================================
54 * This software consists of voluntary contributions made by many
55 * individuals on behalf of the Apache Software Foundation. For more
56 * information on the Apache Software Foundation, please see
57 * <http://www.apache.org/>.
60 public sealed class SegmentTermEnum
: TermEnum
, ICloneable
62 private InputStream input
;
63 private FieldInfos fieldInfos
;
65 internal int position
= -1;
67 private Term term
= new Term("", "");
68 private TermInfo termInfo
= new TermInfo();
70 internal bool isIndex
= false;
71 internal long indexPointer
= 0;
74 private char[] buffer
= {};
76 public SegmentTermEnum(InputStream i
, FieldInfos fis
, bool isi
)
80 size
= input
.ReadInt();
86 SegmentTermEnum clone
= null;
89 clone
= (SegmentTermEnum
)base.MemberwiseClone();
93 clone
.input
= (InputStream
)input
.Clone();
94 clone
.termInfo
= new TermInfo(termInfo
);
95 if (term
!= null) clone
.GrowBuffer(term
.text
.Length
);
100 internal void Seek(long pointer
, int p
, Term t
, TermInfo ti
)
107 GrowBuffer(term
.text
.Length
); // copy term text into buffer
111 /// Increments the enumeration to the next element.
113 /// <returns>true if one exists.</returns>
114 override public bool Next()
116 if (position
++ >= size
-1)
125 termInfo
.docFreq
= input
.ReadVInt(); // read doc freq
126 termInfo
.freqPointer
+= input
.ReadVLong(); // read freq pointer
127 termInfo
.proxPointer
+= input
.ReadVLong(); // read prox pointer
130 indexPointer
+= input
.ReadVLong(); // read index pointer
135 private Term
ReadTerm()
137 int start
= input
.ReadVInt();
138 int length
= input
.ReadVInt();
139 int totalLength
= start
+ length
;
140 if (buffer
.Length
< totalLength
)
141 GrowBuffer(totalLength
);
143 input
.ReadChars(buffer
, start
, length
);
144 return new Term(fieldInfos
.FieldName(input
.ReadVInt()),
145 new String(buffer
, 0, totalLength
), false);
148 private void GrowBuffer(int length
)
150 buffer
= new char[length
];
151 for (int i
= 0; i
< term
.text
.Length
; i
++) // copy contents
152 buffer
[i
] = term
.text
[i
];
156 /// Returns the current Term in the enumeration.
157 /// Initially invalid, valid after Next() called for the first time.
159 /// <returns></returns>
160 override public Term
Term()
166 /// Returns the current TermInfo in the enumeration.
167 /// Initially invalid, valid after Next() called for the first time.
169 /// <returns></returns>
170 public TermInfo
TermInfo()
172 return new TermInfo(termInfo
);
176 /// Sets the argument to the current TermInfo in the enumeration.
177 /// Initially invalid, valid after Next() called for the first time.
179 /// <param name="ti"></param>
180 internal void TermInfo(TermInfo ti
)
186 /// Returns the docFreq from the current termInfo in the enumeration.
187 /// Initially invalid, valid after Next() called for the first time.
189 override public int DocFreq()
191 return termInfo
.docFreq
;
195 /// Returns the freqPointer from the current termInfo in the enumeration.
196 /// Initially invalid, valid after Next() called for the first time.
198 /// <returns></returns>
199 internal long FreqPointer()
201 return termInfo
.freqPointer
;
205 /// Returns the proxPointer from the current termInfo in the enumeration.
206 /// Initially invalid, valid after Next() called for the first time.
208 /// <returns></returns>
209 internal long ProxPointer()
211 return termInfo
.proxPointer
;
215 /// Closes the enumeration to further activity, freeing resources.
217 override public void Close()