public static IProperty GetPropertyMapping(this IElasticQueryVisitorContext context, string field) { if (String.IsNullOrEmpty(field)) { return(null); } return(context.GetPropertyMappingFunc?.Invoke(field)); }
public static bool IsPropertyAnalyzed(this IElasticQueryVisitorContext context, IProperty property) { if (property is ITextProperty textProperty) { return(!textProperty.Index.HasValue || textProperty.Index.Value); } return(false); }
public static bool IsDatePropertyType(this IElasticQueryVisitorContext context, string field) { if (String.IsNullOrEmpty(field)) { return(false); } return(context.GetPropertyMapping(field) is IDateProperty); }
public Task <IEnumerable <IFieldSort> > BuildSortAsync(IQueryNode sort, IElasticQueryVisitorContext context = null) { if (context == null) { context = new ElasticQueryVisitorContext(); } return(GetSortFieldsVisitor.RunAsync(sort, context)); }
public async Task <QueryContainer> BuildQueryAsync(string query, IElasticQueryVisitorContext context = null) { if (context == null) { context = new ElasticQueryVisitorContext(); } var result = await ParseAsync(query, QueryType.Query, context).ConfigureAwait(false); return(await BuildQueryAsync(result, context).ConfigureAwait(false)); }
public async Task <IEnumerable <IFieldSort> > BuildSortAsync(string sort, IElasticQueryVisitorContext context = null) { if (context == null) { context = new ElasticQueryVisitorContext(); } var result = await ParseAsync(sort, QueryType.Sort, context).ConfigureAwait(false); return(await BuildSortAsync(result, context).ConfigureAwait(false)); }
public static bool IsPropertyAnalyzed(this IElasticQueryVisitorContext context, string field) { if (String.IsNullOrEmpty(field)) { return(true); } var property = context.GetPropertyMapping(field); if (property == null) { return(false); } return(context.IsPropertyAnalyzed(property)); }
public static bool IsPropertyAnalyzed(this IElasticQueryVisitorContext context, IProperty property) { if (property is ITextProperty textProperty) { return(!textProperty.Index.HasValue || textProperty.Index.Value); } #pragma warning disable 618 if (property is IStringProperty stringMapping) { return(stringMapping.Index == FieldIndexOption.Analyzed || stringMapping.Index == null); } #pragma warning restore 618 return(false); }
public Task <QueryContainer> BuildQueryAsync(IQueryNode query, IElasticQueryVisitorContext context = null) { if (context == null) { context = new ElasticQueryVisitorContext(); } var q = query.GetQuery() ?? new MatchAllQuery(); if (context?.UseScoring == false) { q = new BoolQuery { Filter = new QueryContainer[] { q } }; } return(Task.FromResult <QueryContainer>(q)); }
public static (string ResolvedField, IProperty Mapping) GetPropertyMapping(this IElasticQueryVisitorContext context, string field, bool resolveAlias = true) { if (String.IsNullOrEmpty(field)) { return(field, null); } string resolvedField = field; var property = context.GetPropertyMappingFunc?.Invoke(field); if (resolveAlias && property is IFieldAliasProperty fieldAlias) { resolvedField = fieldAlias.Path.Name; property = context.GetPropertyMappingFunc?.Invoke(resolvedField); } return(resolvedField, property); }
public static string GetNonAnalyzedFieldName(this IElasticQueryVisitorContext context, string field) { if (String.IsNullOrEmpty(field)) { return(field); } var property = context.GetPropertyMapping(field); if (property == null || !context.IsPropertyAnalyzed(property)) { return(field); } var multiFieldProperty = property as ICoreProperty; if (multiFieldProperty?.Fields == null) { return(field); } var nonAnalyzedProperty = multiFieldProperty.Fields.FirstOrDefault(kvp => { if (kvp.Value is IKeywordProperty) { return(true); } if (!context.IsPropertyAnalyzed(kvp.Value)) { return(true); } return(false); }); if (nonAnalyzedProperty.Value != null) { return(field + "." + nonAnalyzedProperty.Key.Name); } return(field); }
public Task <AggregationContainer> BuildAggregationsAsync(IQueryNode aggregations, IElasticQueryVisitorContext context = null) { return(Task.FromResult <AggregationContainer>(aggregations?.GetAggregation())); }
public async Task <AggregationContainer> BuildAggregationsAsync(string aggregations, IElasticQueryVisitorContext context = null) { if (context == null) { context = new ElasticQueryVisitorContext(); } var result = await ParseAsync(aggregations, QueryType.Aggregation, context).ConfigureAwait(false); return(await BuildAggregationsAsync(result, context).ConfigureAwait(false)); }
public static FieldType GetFieldType(this IElasticQueryVisitorContext context, string field) { if (String.IsNullOrWhiteSpace(field)) { return(FieldType.None); } var mapping = context.GetPropertyMapping(field); if (mapping?.Type == null) { return(FieldType.None); } switch (mapping.Type.Name) { case "geo_point": return(FieldType.GeoPoint); case "geo_shape": return(FieldType.GeoShape); case "attachment": return(FieldType.Attachment); case "ip": return(FieldType.Ip); case "binary": return(FieldType.Binary); case "string": return(FieldType.String); case "keyword": return(FieldType.Keyword); case "text": return(FieldType.Text); case "date": return(FieldType.Date); case "boolean": return(FieldType.Boolean); case "completion": return(FieldType.Completion); case "nested": return(FieldType.Nested); case "object": return(FieldType.Object); case "murmur3": return(FieldType.Murmur3Hash); case "token_count": return(FieldType.TokenCount); case "percolator": return(FieldType.Percolator); case "integer": return(FieldType.Integer); case "long": return(FieldType.Long); case "short": return(FieldType.Short); case "byte": return(FieldType.Byte); case "float": return(FieldType.Float); case "half_float": return(FieldType.HalfFloat); case "scaled_float": return(FieldType.ScaledFloat); case "double": return(FieldType.Double); case "integer_range": return(FieldType.IntegerRange); case "float_range": return(FieldType.FloatRange); case "long_range": return(FieldType.LongRange); case "double_range": return(FieldType.DoubleRange); case "date_range": return(FieldType.DateRange); case "ip_range": return(FieldType.IpRange); default: return(FieldType.None); } }