Update the thread-local storage patch, to fix #335178
[beagle.git] / beagled / Lucene.Net / Index / SegmentTermVector.cs
blobe72701d9a383af3eaa90e7fbf7d8a38138dfffab
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 public 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 if (terms != null)
49 for (int i = 0; i < terms.Length; i++)
51 if (i > 0)
52 sb.Append(", ");
53 sb.Append(terms[i]).Append('/').Append(termFreqs[i]);
56 sb.Append('}');
58 return sb.ToString();
61 public virtual int Size()
63 return terms == null?0:terms.Length;
66 public virtual System.String[] GetTerms()
68 return terms;
71 public virtual int[] GetTermFrequencies()
73 return termFreqs;
76 public virtual int IndexOf(System.String termText)
78 if (terms == null)
79 return - 1;
80 int res = System.Array.BinarySearch(terms, termText);
81 return res >= 0?res:- 1;
84 public virtual int[] IndexesOf(System.String[] termNumbers, int start, int len)
86 // TODO: there must be a more efficient way of doing this.
87 // At least, we could advance the lower bound of the terms array
88 // as we find valid indexes. Also, it might be possible to leverage
89 // this even more by starting in the middle of the termNumbers array
90 // and thus dividing the terms array maybe in half with each found index.
91 int[] res = new int[len];
93 for (int i = 0; i < len; i++)
95 res[i] = IndexOf(termNumbers[start + i]);
97 return res;