cvsimport
[beagle.git] / beagled / Lucene.Net / Index / SegmentTermVector.cs
blob09e80785d988706abfed21fee3cb4436fbfbb32f
1 /*
2 * Copyright 2004 The Apache Software Foundation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 using System;
19 namespace Lucene.Net.Index
23 public class SegmentTermVector : TermFreqVector
25 private System.String field;
26 private System.String[] terms;
27 private int[] termFreqs;
29 internal SegmentTermVector(System.String field, System.String[] terms, int[] termFreqs)
31 this.field = field;
32 this.terms = terms;
33 this.termFreqs = termFreqs;
36 /// <summary> </summary>
37 /// <returns> The number of the field this vector is associated with
38 /// </returns>
39 public virtual System.String GetField()
41 return field;
44 public override System.String ToString()
46 System.Text.StringBuilder sb = new System.Text.StringBuilder();
47 sb.Append('{');
48 sb.Append(field).Append(": ");
49 if (terms != null)
51 for (int i = 0; i < terms.Length; i++)
53 if (i > 0)
54 sb.Append(", ");
55 sb.Append(terms[i]).Append('/').Append(termFreqs[i]);
58 sb.Append('}');
60 return sb.ToString();
63 public virtual int Size()
65 return terms == null?0:terms.Length;
68 public virtual System.String[] GetTerms()
70 return terms;
73 public virtual int[] GetTermFrequencies()
75 return termFreqs;
78 public virtual int IndexOf(System.String termText)
80 if (terms == null)
81 return - 1;
82 int res = System.Array.BinarySearch(terms, termText);
83 return res >= 0?res:- 1;
86 public virtual int[] IndexesOf(System.String[] termNumbers, int start, int len)
88 // TODO: there must be a more efficient way of doing this.
89 // At least, we could advance the lower bound of the terms array
90 // as we find valid indexes. Also, it might be possible to leverage
91 // this even more by starting in the middle of the termNumbers array
92 // and thus dividing the terms array maybe in half with each found index.
93 int[] res = new int[len];
95 for (int i = 0; i < len; i++)
97 res[i] = IndexOf(termNumbers[start + i]);
99 return res;