-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
SearchHighlight.cs
105 lines (95 loc) · 3.38 KB
/
SearchHighlight.cs
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/* Copyright 2010-present MongoDB Inc.
*
* Licensed 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.
*/
using MongoDB.Bson;
using MongoDB.Bson.Serialization.Attributes;
namespace MongoDB.Driver.Search
{
/// <summary>
/// Represents a result of highlighting.
/// </summary>
public sealed class SearchHighlight
{
/// <summary>
/// Initializes a new instance of the <see cref="SearchHighlight"/> class.
/// </summary>
/// <param name="path">document field which returned a match.</param>
/// <param name="score">Score assigned to this result.</param>
/// <param name="texts">Objects containing the matching text and the surrounding text.</param>
public SearchHighlight(string path, double score, SearchHighlightText[] texts)
{
Path = path;
Score = score;
Texts = texts;
}
/// <summary>
/// Gets the document field which returned a match.
/// </summary>
[BsonElement("path")]
public string Path { get; }
/// <summary>
/// Gets the score assigned to this result.
/// </summary>
[BsonElement("score")]
public double Score { get; }
/// <summary>
/// Gets one or more objects containing the matching text and the surrounding text
/// (if any).
/// </summary>
[BsonDefaultValue(null)]
[BsonElement("texts")]
public SearchHighlightText[] Texts { get; }
}
/// <summary>
/// Represents the matching text or the surrounding text of a highlighting result.
/// </summary>
public sealed class SearchHighlightText
{
/// <summary>
/// Initializes a new instance of the <see cref="SearchHighlightText"/> class.
/// </summary>
/// <param name="type">Type of search highlight.</param>
/// <param name="value">Text from the field which returned a match.</param>
public SearchHighlightText(HighlightTextType type, string value)
{
Type = type;
Value = value;
}
/// <summary>
/// Gets or sets the type of text, matching or surrounding.
/// </summary>
[BsonElement("type")]
[BsonRepresentation(BsonType.String)]
public HighlightTextType Type { get; }
/// <summary>
/// Gets the text from the field which returned a match.
/// </summary>
[BsonElement("value")]
public string Value { get; }
}
/// <summary>
/// Represents the type of text in a highlighting result, matching or surrounding.
/// </summary>
public enum HighlightTextType
{
/// <summary>
/// Indicates that the text contains a match.
/// </summary>
Hit,
/// <summary>
/// Indicates that the text contains the text content adjacent to a matching string.
/// </summary>
Text
}
}