1 package org.apache.lucene.index;
4 * Licensed to the Apache Software Foundation (ASF) under one or more
5 * contributor license agreements. See the NOTICE file distributed with
6 * this work for additional information regarding copyright ownership.
7 * The ASF licenses this file to You under the Apache License, Version 2.0
8 * (the "License"); you may not use this file except in compliance with
9 * the License. You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
23 class SegmentTermVector implements TermFreqVector {
25 private String terms[];
26 private int termFreqs[];
28 SegmentTermVector(String field, String terms[], int termFreqs[]) {
31 this.termFreqs = termFreqs;
36 * @return The number of the field this vector is associated with
38 public String getField() {
43 public String toString() {
44 StringBuilder sb = new StringBuilder();
46 sb.append(field).append(": ");
48 for (int i=0; i<terms.length; i++) {
49 if (i>0) sb.append(", ");
50 sb.append(terms[i]).append('/').append(termFreqs[i]);
59 return terms == null ? 0 : terms.length;
62 public String [] getTerms() {
66 public int[] getTermFrequencies() {
70 public int indexOf(String termText) {
73 int res = Arrays.binarySearch(terms, termText);
74 return res >= 0 ? res : -1;
77 public int[] indexesOf(String [] termNumbers, int start, int len) {
78 // TODO: there must be a more efficient way of doing this.
79 // At least, we could advance the lower bound of the terms array
80 // as we find valid indexes. Also, it might be possible to leverage
81 // this even more by starting in the middle of the termNumbers array
82 // and thus dividing the terms array maybe in half with each found index.
83 int res[] = new int[len];
85 for (int i=0; i < len; i++) {
86 res[i] = indexOf(termNumbers[start+ i]);