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 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(": ");
47 for (int i
= 0; i
< terms
.Length
; i
++)
51 sb
.Append(terms
[i
]).Append('/').Append(termFreqs
[i
]);
57 public virtual int Size()
59 return terms
== null?0:terms
.Length
;
62 public virtual System
.String
[] GetTerms()
67 public virtual int[] GetTermFrequencies()
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
]);