Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/Nest/DSL/HighlightFieldDescriptor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ public class HighlightFieldDescriptor<T> where T : class
[JsonProperty("type")]
internal string _Type { get; set; }

[JsonProperty("force_source")]
internal bool? _ForceSource { get; set; }

public HighlightFieldDescriptor<T> OnField(string field)
{
this._Field = field;
Expand All @@ -67,6 +70,11 @@ public HighlightFieldDescriptor<T> TagsSchema(string schema = "styled")
this._TagsSchema = schema;
return this;
}
public HighlightFieldDescriptor<T> ForceSource(bool force = true)
{
this._ForceSource = force;
return this;
}
public HighlightFieldDescriptor<T> Type(string type)
{
this._Type = type;
Expand Down
2 changes: 2 additions & 0 deletions src/Nest/DSL/IQueryDescriptor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ interface IQueryDescriptor<T>
BaseQuery Bool(Action<BoolQueryDescriptor<T>> booleanQuery);
BaseQuery Boosting(Action<BoostingQueryDescriptor<T>> boostingQuery);
BaseQuery ConstantScore(Action<ConstantScoreQueryDescriptor<T>> selector);
[Obsolete("Custom boost factor has been removed in 1.1")]
BaseQuery CustomBoostFactor(Action<CustomBoostFactorQueryDescriptor<T>> selector);
[Obsolete("Custom score has been removed in 1.1")]
BaseQuery CustomScore(Action<CustomScoreQueryDescriptor<T>> customScoreQuery);
BaseQuery Dismax(Action<DismaxQueryDescriptor<T>> selector);
BaseQuery Filtered(Action<FilteredQueryDescriptor<T>> selector);
Expand Down
55 changes: 55 additions & 0 deletions src/Nest/DSL/Query/GeoShapeQueryDescriptor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using Nest.Resolvers;
using Newtonsoft.Json;
using Elasticsearch.Net;

namespace Nest
{
public class GeoShapeQueryDescriptor<T> : IQuery
where T : class
{
internal PropertyPathMarker _Field { get; set; }
bool IQuery.IsConditionless
{
get
{
return this._Field.IsConditionless() || (this._Shape == null || !this._Shape.Coordinates.HasAny());
}

}
public GeoShapeQueryDescriptor<T> OnField(string field)
{
this._Field = field;
return this;
}
public GeoShapeQueryDescriptor<T> OnField(Expression<Func<T, object>> objectPath)
{
this._Field = objectPath;
return this;
}
[JsonProperty("shape")]
internal GeoShapeVector _Shape { get; set; }

public GeoShapeQueryDescriptor<T> Type(string type)
{
if (this._Shape == null)
this._Shape = new GeoShapeVector();
this._Shape.Type = type;
return this;
}

public GeoShapeQueryDescriptor<T> Coordinates(IEnumerable<IEnumerable<double>> coordinates)
{
if (this._Shape == null)
this._Shape = new GeoShapeVector();
this._Shape.Coordinates = coordinates;
return this;
}

}

}
2 changes: 1 addition & 1 deletion src/Nest/DSL/Query/QueryStringDescriptor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public QueryStringDescriptor<T> Query(string query)
this._QueryString = query;
return this;
}
public QueryStringDescriptor<T> Operator(Operator op)
public QueryStringDescriptor<T> DefaultOperator(Operator op)
{
this._DefaultOperator = op;
return this;
Expand Down
113 changes: 113 additions & 0 deletions src/Nest/DSL/Query/SimpeQueryStringQueryDescriptor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Newtonsoft.Json;
using System.Linq.Expressions;
using System.Globalization;
using Newtonsoft.Json.Converters;
using Elasticsearch.Net;
using Nest.Resolvers;

namespace Nest
{
[JsonObject(MemberSerialization = MemberSerialization.OptIn)]
public class SimpleQueryStringQueryDescriptor<T> : IQuery where T : class
{
[JsonProperty(PropertyName = "query")]
internal string _QueryString { get; set; }
[JsonProperty(PropertyName = "default_field")]
internal PropertyPathMarker _Field { get; set; }
[JsonProperty(PropertyName = "fields")]
internal IEnumerable<PropertyPathMarker> _Fields { get; set; }
[JsonProperty(PropertyName = "default_operator")]
[JsonConverter(typeof(StringEnumConverter))]
internal Operator? _DefaultOperator { get; set; }
[JsonProperty(PropertyName = "analyzer")]
internal string _Analyzer { get; set; }
[JsonProperty(PropertyName = "lowercase_expanded_terms")]
internal bool? _LowercaseExpendedTerms { get; set; }
[JsonProperty(PropertyName = "flags")]
internal string _Flags { get; set; }
[JsonProperty(PropertyName = "locale")]
internal string _Locale { get; set; }


bool IQuery.IsConditionless
{
get
{
return this._QueryString.IsNullOrEmpty();
}
}


public SimpleQueryStringQueryDescriptor<T> OnField(string field)
{
this._Field = field;
return this;
}
public SimpleQueryStringQueryDescriptor<T> OnField(Expression<Func<T, object>> objectPath)
{
this._Field = objectPath;
return this;
}
public SimpleQueryStringQueryDescriptor<T> OnFields(IEnumerable<string> fields)
{
this._Fields = fields.Select(f=>(PropertyPathMarker)f);
return this;
}
public SimpleQueryStringQueryDescriptor<T> OnFields(
params Expression<Func<T, object>>[] objectPaths)
{
this._Fields = objectPaths.Select(e=>(PropertyPathMarker)e);
return this;
}
public SimpleQueryStringQueryDescriptor<T> OnFieldsWithBoost(Action<FluentDictionary<Expression<Func<T, object>>, double?>> boostableSelector)
{
var d = new FluentDictionary<Expression<Func<T, object>>, double?>();
boostableSelector(d);
this._Fields = d.Select(o => PropertyPathMarker.Create(o.Key, o.Value));
return this;
}
public SimpleQueryStringQueryDescriptor<T> OnFieldsWithBoost(Action<FluentDictionary<string, double?>> boostableSelector)
{
var d = new FluentDictionary<string, double?>();
boostableSelector(d);
this._Fields = d.Select(o => PropertyPathMarker.Create(o.Key, o.Value));
return this;
}

public SimpleQueryStringQueryDescriptor<T> Query(string query)
{
this._QueryString = query;
return this;
}
public SimpleQueryStringQueryDescriptor<T> DefaultOperator(Operator op)
{
this._DefaultOperator = op;
return this;
}
public SimpleQueryStringQueryDescriptor<T> Analyzer(string analyzer)
{
this._Analyzer = analyzer;
return this;
}
public SimpleQueryStringQueryDescriptor<T> Flags(string flags)
{
this._Flags = flags;
return this;
}
public SimpleQueryStringQueryDescriptor<T> LowercaseExpendedTerms(bool lowercaseExpendedTerms)
{
this._LowercaseExpendedTerms = lowercaseExpendedTerms;
return this;
}
public SimpleQueryStringQueryDescriptor<T> Locale(string locale)
{
this._Locale = locale;
return this;
}

}
}
38 changes: 38 additions & 0 deletions src/Nest/DSL/QueryDescriptor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,14 @@ internal QueryDescriptor(bool forceConditionless)
[JsonConverter(typeof(DictionaryKeysAreNotPropertyNamesJsonConverter))]
[JsonProperty(PropertyName = "fuzzy")]
internal IDictionary<PropertyPathMarker, object> FuzzyQueryDescriptor { get; set; }
[JsonProperty(PropertyName = "geo_shape")]
[JsonConverter(typeof(DictionaryKeysAreNotPropertyNamesJsonConverter))]
internal IDictionary<PropertyPathMarker, object> GeoShapeQueryDescriptor { get; set; }
[JsonProperty(PropertyName = "terms")]
[JsonConverter(typeof(DictionaryKeysAreNotPropertyNamesJsonConverter))]
internal IDictionary<PropertyPathMarker, object> TermsQueryDescriptor { get; set; }
[JsonProperty(PropertyName = "simple_query_string")]
internal SimpleQueryStringQueryDescriptor<T> SimpleQueryStringDescriptor { get; set; }
[JsonProperty(PropertyName = "query_string")]
internal QueryStringDescriptor<T> QueryStringDescriptor { get; set; }
[JsonProperty(PropertyName = "regexp")]
Expand Down Expand Up @@ -160,6 +165,20 @@ public BaseQuery QueryString(Action<QueryStringDescriptor<T>> selector)
selector(query);
return this.New(query, q => q.QueryStringDescriptor = query);
}

/// <summary>
/// A query that uses the SimpleQueryParser to parse its context.
/// Unlike the regular query_string query, the simple_query_string query will
/// never throw an exception, and discards invalid parts of the query.
/// </summary>
public BaseQuery SimpleQueryString(Action<SimpleQueryStringQueryDescriptor<T>> selector)
{
var query = new SimpleQueryStringQueryDescriptor<T>();
selector(query);
return this.New(query, q => q.SimpleQueryStringDescriptor = query);
}


/// <summary>
/// A query that match on any (configurable) of the provided terms. This is a simpler syntax query for using a bool query with several term queries in the should clauses.
/// </summary>
Expand Down Expand Up @@ -417,6 +436,23 @@ public BaseQuery MoreLikeThis(Action<MoreLikeThisQueryDescriptor<T>> selector)

return this.New(query, q => q.MoreLikeThisDescriptor = query);
}

/// <summary>
/// The geo_shape Filter uses the same grid square representation as the geo_shape mapping to find documents
/// that have a shape that intersects with the query shape.
/// It will also use the same PrefixTree configuration as defined for the field mapping.
/// </summary>
public BaseQuery GeoShape(Action<GeoShapeQueryDescriptor<T>> selector)
{
var query = new GeoShapeQueryDescriptor<T>();
selector(query);
var shape = new Dictionary<PropertyPathMarker, object>
{
{ query._Field, query }
};
return this.New(query, q => q.GeoShapeQueryDescriptor = shape);
}

/// <summary>
/// The has_child query works the same as the has_child filter, by automatically wrapping the filter with a
/// constant_score.
Expand Down Expand Up @@ -493,6 +529,7 @@ public BaseQuery ConstantScore(Action<ConstantScoreQueryDescriptor<T>> selector)
/// This can sometimes be desired since boost value set on specific queries gets normalized, while this
/// query boost factor does not.
/// </summary>
[Obsolete("Custom boost factor has been removed in 1.1")]
public BaseQuery CustomBoostFactor(Action<CustomBoostFactorQueryDescriptor<T>> selector)
{
var query = new CustomBoostFactorQueryDescriptor<T>();
Expand All @@ -504,6 +541,7 @@ public BaseQuery CustomBoostFactor(Action<CustomBoostFactorQueryDescriptor<T>> s
/// custom_score query allows to wrap another query and customize the scoring of it optionally with a
/// computation derived from other field values in the doc (numeric ones) using script expression
/// </summary>
[Obsolete("Custom score has been removed in 1.1")]
public BaseQuery CustomScore(Action<CustomScoreQueryDescriptor<T>> customScoreQuery)
{
var query = new CustomScoreQueryDescriptor<T>();
Expand Down
11 changes: 11 additions & 0 deletions src/Nest/Domain/DSL/Query.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,13 @@ public static BaseQuery ConstantScore(Action<ConstantScoreQueryDescriptor<T>> se
return new QueryDescriptor<T>().ConstantScore(selector);
}

[Obsolete("Custom boost factor has been removed in 1.1")]
public static BaseQuery CustomBoostFactor(Action<CustomBoostFactorQueryDescriptor<T>> selector)
{
return new QueryDescriptor<T>().CustomBoostFactor(selector);
}

[Obsolete("Custom score has been removed in 1.1")]
public static BaseQuery CustomScore(Action<CustomScoreQueryDescriptor<T>> customScoreQuery)
{
return new QueryDescriptor<T>().CustomScore(customScoreQuery);
Expand Down Expand Up @@ -128,6 +130,15 @@ public static BaseQuery Prefix(string field, string value, double? Boost = null)
return new QueryDescriptor<T>().Prefix(field, value, Boost);
}

public static BaseQuery SimpleQueryString(Action<SimpleQueryStringQueryDescriptor<T>> selector)
{
return new QueryDescriptor<T>().SimpleQueryString(selector);
}

public static BaseQuery GeoShape(Action<GeoShapeQueryDescriptor<T>> selector)
{
return new QueryDescriptor<T>().GeoShape(selector);
}
public static BaseQuery QueryString(Action<QueryStringDescriptor<T>> selector)
{
return new QueryDescriptor<T>().QueryString(selector);
Expand Down
2 changes: 2 additions & 0 deletions src/Nest/Nest.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,8 @@
<Compile Include="DSL\Facets\Ip4Range.cs" />
<Compile Include="DSL\Facets\DateExpressionRange.cs" />
<Compile Include="DSL\Paths\BasePathDescriptor.cs" />
<Compile Include="DSL\Query\GeoShapeQueryDescriptor.cs" />
<Compile Include="DSL\Query\SimpeQueryStringQueryDescriptor.cs" />
<Compile Include="DSL\SourceDescriptor.cs" />
<Compile Include="DSL\NodesStatsDescriptor.cs" />
<Compile Include="DSL\NodesInfoDescriptor.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public void TestHighlight()
.OnField(e => e.Content)
.PreTags("<em>")
.PostTags("</em>")

)
)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ public void MapFluentFull()
)
.String(s => s
.Name(p => p.Name)

.IndexName("my_crazy_name_i_want_in_lucene")
.IncludeInAll()
.Index(FieldIndexOption.analyzed)
Expand Down
4 changes: 4 additions & 0 deletions src/Tests/Nest.Tests.Unit/Nest.Tests.Unit.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@
<Compile Include="Search\Filter\Singles\HasParentFilterJson.cs" />
<Compile Include="Search\Query\Modes\ConditionlessQueryJson.cs" />
<Compile Include="Search\Query\Singles\FunctionScoreQueryJson.cs" />
<Compile Include="Search\Query\Singles\SimpleQueryString\SimpleQueryStringQueryJson.cs" />
<Compile Include="Search\Query\Singles\RegexpQueryJson.cs" />
<Compile Include="Search\Query\Singles\HasParentQueryJson.cs" />
<Compile Include="Search\Query\Singles\MultiMatch\MultiMatchJson.cs" />
Expand Down Expand Up @@ -503,6 +504,9 @@
<None Include="Search\Query\Modes\VerbatimDoesNotThrowOnEmptyTerm.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="Search\Query\Singles\SimpleQueryString\SimpleQueryStringFull.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="Search\Query\Singles\Terms\TermsQueryDescriptorUsingExternalField.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"from": 0,
"size": 10,
"query": {
"geo_shape": {
"myGeoShape": {
"shape": {
"type": "enveloppe",
"coordinates": [
[ 13.0, 53.0 ], [ 14.0, 52.0 ]
]
}
}
}
}
}
Loading