forked from apache/lucenenet
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWeightedSpanTerm.cs
More file actions
80 lines (70 loc) · 2.92 KB
/
Copy pathWeightedSpanTerm.cs
File metadata and controls
80 lines (70 loc) · 2.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
using System.Collections.Generic;
using JCG = J2N.Collections.Generic;
namespace Lucene.Net.Search.Highlight
{
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/// <summary>
/// Lightweight class to hold term, weight, and positions used for scoring this term.
/// </summary>
public class WeightedSpanTerm : WeightedTerm
{
private bool _positionSensitive;
private readonly JCG.List<PositionSpan> _positionSpans = new JCG.List<PositionSpan>();
public WeightedSpanTerm(float weight, string term)
: base(weight, term)
{
// LUCENENET NOTE: Duplicate instantiation
//_positionSpans = new List<PositionSpan>();
}
public WeightedSpanTerm(float weight, string term, bool positionSensitive)
: base(weight, term)
{
_positionSensitive = positionSensitive;
}
/// <summary>
/// Checks to see if this term is valid at <paramref name="position"/>.
/// </summary>
/// <param name="position">to check against valid term positions</param>
/// <returns>true iff this term is a hit at this position</returns>
public virtual bool CheckPosition(int position)
{
// There would probably be a slight speed improvement if PositionSpans
// where kept in some sort of priority queue - that way this method
// could
// bail early without checking each PositionSpan.
foreach (var positionSpan in _positionSpans)
{
if ((position >= positionSpan.Start) && (position <= positionSpan.End))
{
return true;
}
}
return false;
}
public virtual void AddPositionSpans(IList<PositionSpan> positionSpans)
{
this._positionSpans.AddRange(positionSpans);
}
public virtual bool IsPositionSensitive
{
get => _positionSensitive;
set => this._positionSensitive = value;
}
public virtual IList<PositionSpan> PositionSpans => _positionSpans;
}
}