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.
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
)
33 this.termFreqs
= termFreqs
;
36 /// <summary> </summary>
37 /// <returns> The number of the field this vector is associated with
39 public virtual System
.String
GetField()
44 public override System
.String
ToString()
46 System
.Text
.StringBuilder sb
= new System
.Text
.StringBuilder();
48 sb
.Append(field
).Append(": ");
51 for (int i
= 0; i
< terms
.Length
; i
++)
55 sb
.Append(terms
[i
]).Append('/').Append(termFreqs
[i
]);
63 public virtual int Size()
65 return terms
== null?0:terms
.Length
;
68 public virtual System
.String
[] GetTerms()
73 public virtual int[] GetTermFrequencies()
78 public virtual int IndexOf(System
.String termText
)
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
]);