-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
Copy pathConstantScoreQueryDescriptor.cs
91 lines (77 loc) · 2.83 KB
/
ConstantScoreQueryDescriptor.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
using System;
using System.Collections.Generic;
using System.Linq;
using Nest.Resolvers.Converters;
using Newtonsoft.Json;
namespace Nest
{
[JsonObject(MemberSerialization = MemberSerialization.OptIn)]
[JsonConverter(typeof(ReadAsTypeConverter<ConstantScoreQueryDescriptor<object>>))]
public interface IConstantScoreQuery : IQuery
{
[JsonProperty(PropertyName = "query")]
[JsonConverter(typeof(CompositeJsonConverter<ReadAsTypeConverter<QueryDescriptor<object>>, CustomJsonConverter>))]
IQueryContainer Query { get; set; }
[JsonProperty(PropertyName = "filter")]
[JsonConverter(typeof(CompositeJsonConverter<ReadAsTypeConverter<FilterContainer>, CustomJsonConverter>))]
IFilterContainer Filter { get; set; }
[JsonProperty(PropertyName = "boost")]
double? Boost { get; set; }
}
public class ConstantScoreQuery : PlainQuery, IConstantScoreQuery
{
protected override void WrapInContainer(IQueryContainer container)
{
container.ConstantScore = this;
}
public bool IsConditionless { get { return false; } }
public string Lang { get; set; }
public string Script { get; set; }
public Dictionary<string, object> Params { get; set; }
public IQueryContainer Query { get; set; }
public IFilterContainer Filter { get; set; }
public double? Boost { get; set; }
}
public class ConstantScoreQueryDescriptor<T> : IConstantScoreQuery where T : class
{
IQueryContainer IConstantScoreQuery.Query { get; set; }
IFilterContainer IConstantScoreQuery.Filter { get; set; }
double? IConstantScoreQuery.Boost { get; set; }
bool IQuery.IsConditionless
{
get
{
if (((IConstantScoreQuery)this).Query == null && ((IConstantScoreQuery)this).Filter == null)
return true;
if (((IConstantScoreQuery)this).Filter == null && ((IConstantScoreQuery)this).Query != null)
return ((IConstantScoreQuery)this).Query.IsConditionless;
if (((IConstantScoreQuery)this).Filter != null && ((IConstantScoreQuery)this).Query == null)
return ((IConstantScoreQuery)this).Filter.IsConditionless;
return false;
}
}
public ConstantScoreQueryDescriptor<T> Query(Func<QueryDescriptor<T>, QueryContainer> querySelector)
{
querySelector.ThrowIfNull("querySelector");
((IConstantScoreQuery)this).Filter = null;
var query = new QueryDescriptor<T>();
var q = querySelector(query);
((IConstantScoreQuery)this).Query = q;
return this;
}
public ConstantScoreQueryDescriptor<T> Filter(Func<FilterDescriptor<T>, FilterContainer> filterSelector)
{
filterSelector.ThrowIfNull("filterSelector");
((IConstantScoreQuery)this).Query = null;
var filter = new FilterDescriptor<T>();
var f = filterSelector(filter);
((IConstantScoreQuery)this).Filter = f;
return this;
}
public ConstantScoreQueryDescriptor<T> Boost(double boost)
{
((IConstantScoreQuery)this).Boost = boost;
return this;
}
}
}