2 * Copyright 2004 The Apache Software Foundation
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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 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
)
31 this.termFreqs
= termFreqs
;
34 /// <summary> </summary>
35 /// <returns> The number of the Field this vector is associated with
37 public virtual System
.String
GetField()
42 public override System
.String
ToString()
44 System
.Text
.StringBuilder sb
= new System
.Text
.StringBuilder();
46 sb
.Append(field
).Append(": ");
49 for (int i
= 0; i
< terms
.Length
; i
++)
53 sb
.Append(terms
[i
]).Append('/').Append(termFreqs
[i
]);
61 public virtual int Size()
63 return terms
== null?0:terms
.Length
;
66 public virtual System
.String
[] GetTerms()
71 public virtual int[] GetTermFrequencies()
76 public virtual int IndexOf(System
.String termText
)
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
]);