Thumbnail file hits. Based on a patch from D Bera
[beagle.git] / beagled / Lucene.Net / Index / SegmentTermVector.cs
blobc4e2288e3510cd26195a9210eb51413fda881106
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.
16 using System;
17 namespace Lucene.Net.Index
21 class SegmentTermVector : TermFreqVector
23 private System.String field;
24 private System.String[] terms;
25 private int[] termFreqs;
27 internal SegmentTermVector(System.String field, System.String[] terms, int[] termFreqs)
29 this.field = field;
30 this.terms = terms;
31 this.termFreqs = termFreqs;
34 /// <summary> </summary>
35 /// <returns> The number of the Field this vector is associated with
36 /// </returns>
37 public virtual System.String GetField()
39 return field;
42 public override System.String ToString()
44 System.Text.StringBuilder sb = new System.Text.StringBuilder();
45 sb.Append('{');
46 sb.Append(field).Append(": ");
47 for (int i = 0; i < terms.Length; i++)
49 if (i > 0)
50 sb.Append(", ");
51 sb.Append(terms[i]).Append('/').Append(termFreqs[i]);
53 sb.Append('}');
54 return sb.ToString();
57 public virtual int Size()
59 return terms == null?0:terms.Length;
62 public virtual System.String[] GetTerms()
64 return terms;
67 public virtual int[] GetTermFrequencies()
69 return termFreqs;
72 public virtual int IndexOf(System.String termText)
74 int res = System.Array.BinarySearch(terms, termText);
75 return res >= 0?res:- 1;
78 public virtual int[] IndexesOf(System.String[] termNumbers, int start, int len)
80 // TODO: there must be a more efficient way of doing this.
81 // At least, we could advance the lower bound of the terms array
82 // as we find valid indexes. Also, it might be possible to leverage
83 // this even more by starting in the middle of the termNumbers array
84 // and thus dividing the terms array maybe in half with each found index.
85 int[] res = new int[len];
87 for (int i = 0; i < len; i++)
89 res[i] = IndexOf(termNumbers[i]);
91 return res;