01: package org.apache.lucene.index;
02:
03: /**
04: * Licensed to the Apache Software Foundation (ASF) under one or more
05: * contributor license agreements. See the NOTICE file distributed with
06: * this work for additional information regarding copyright ownership.
07: * The ASF licenses this file to You under the Apache License, Version 2.0
08: * (the "License"); you may not use this file except in compliance with
09: * the License. You may obtain a copy of the License at
10: *
11: * http://www.apache.org/licenses/LICENSE-2.0
12: *
13: * Unless required by applicable law or agreed to in writing, software
14: * distributed under the License is distributed on an "AS IS" BASIS,
15: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16: * See the License for the specific language governing permissions and
17: * limitations under the License.
18: */
19:
20: class SegmentTermPositionVector extends SegmentTermVector implements
21: TermPositionVector {
22: protected int[][] positions;
23: protected TermVectorOffsetInfo[][] offsets;
24: public static final int[] EMPTY_TERM_POS = new int[0];
25:
26: public SegmentTermPositionVector(String field, String terms[],
27: int termFreqs[], int[][] positions,
28: TermVectorOffsetInfo[][] offsets) {
29: super (field, terms, termFreqs);
30: this .offsets = offsets;
31: this .positions = positions;
32: }
33:
34: /**
35: * Returns an array of TermVectorOffsetInfo in which the term is found.
36: *
37: * @param index The position in the array to get the offsets from
38: * @return An array of TermVectorOffsetInfo objects or the empty list
39: * @see org.apache.lucene.analysis.Token
40: */
41: public TermVectorOffsetInfo[] getOffsets(int index) {
42: TermVectorOffsetInfo[] result = TermVectorOffsetInfo.EMPTY_OFFSET_INFO;
43: if (offsets == null)
44: return null;
45: if (index >= 0 && index < offsets.length) {
46: result = offsets[index];
47: }
48: return result;
49: }
50:
51: /**
52: * Returns an array of positions in which the term is found.
53: * Terms are identified by the index at which its number appears in the
54: * term String array obtained from the <code>indexOf</code> method.
55: */
56: public int[] getTermPositions(int index) {
57: int[] result = EMPTY_TERM_POS;
58: if (positions == null)
59: return null;
60: if (index >= 0 && index < positions.length) {
61: result = positions[index];
62: }
63:
64: return result;
65: }
66: }
|