void CompleteHitTranslation(Expression evaluated)
        {
            Visit(evaluated);
            searchRequest.DocumentType = Mapping.GetDocumentType(SourceType);

            if (materializer == null)
                materializer = new ListHitsElasticMaterializer(itemProjector ?? DefaultItemProjector, finalItemType ?? SourceType);
            else if (materializer is ChainMaterializer && ((ChainMaterializer)materializer).Next == null)
                ((ChainMaterializer)materializer).Next = new ListHitsElasticMaterializer(itemProjector ?? DefaultItemProjector, finalItemType ?? SourceType);
        }
Beispiel #2
0
        void CompleteHitTranslation(Expression evaluated)
        {
            this.Visit(evaluated);
            this.searchRequest.DocumentType = Mapping.GetDocumentType(this.SourceType);

            if (materializer == null)
            {
                materializer = new ListHitsElasticMaterializer(itemProjector ?? DefaultItemProjector, finalItemType ?? SourceType);
            }
            else if (materializer is ChainMaterializer && ((ChainMaterializer)materializer).Next == null)
            {
                ((ChainMaterializer)materializer).Next = new ListHitsElasticMaterializer(itemProjector ?? DefaultItemProjector, finalItemType ?? SourceType);
            }
        }
        private ElasticTranslateResult Translate(Expression e)
        {
            var evaluated = PartialEvaluator.Evaluate(e);

            Visit(evaluated);

            searchRequest.Type = mapping.GetDocumentType(type);
            if (searchRequest.Filter == null && searchRequest.Query == null)
            {
                searchRequest.Filter = mapping.GetTypeExistsCriteria(type);
            }

            if (materializer == null)
            {
                materializer = new ElasticManyHitsMaterializer(itemProjector ?? DefaultItemProjector, finalItemType ?? type);
            }

            return(new ElasticTranslateResult(searchRequest, materializer));
        }
        ElasticTranslateResult TranslateIndex <T, TAggregate>(Expression <Func <T, TAggregate> > fieldExpression)
        {
            if (Mapping.TryGetFieldName(typeof(T), fieldExpression.Body, out var field))
            {
                var propertyMappings = Mapping.ElasticPropertyMappings();

                if (propertyMappings.TryGetValue(field, out var propertyType) && propertyType == "text")
                {
                    if (propertyMappings.ContainsKey($"{field}.keyword"))
                    {
                        field = $"{field}.keyword";
                    }
                }

                searchRequest.Size    = 0;
                materializer          = new IndexerMaterializer(field, typeof(TAggregate));
                searchRequest.Indexer = new AggregationCriteria(field);
                return(new ElasticTranslateResult(searchRequest, materializer));
            }
            throw new NotSupportedException("No mapping found for " + fieldExpression.ToString());
        }
        Expression VisitHighlight(Expression source, Expression highlightExpression, Expression configExpression)
        {
            var unaryExpression = highlightExpression as UnaryExpression;

            if (unaryExpression == null)
            {
                throw new NotSupportedException("Highlight expression specify only one property");
            }

            var lambdaExpression = unaryExpression.Operand as LambdaExpression;

            if (lambdaExpression == null)
            {
                throw new NotSupportedException("Highlight expression must be lambda");
            }

            var bodyExpression = lambdaExpression.Body as MemberExpression;

            if (bodyExpression == null)
            {
                throw new NotSupportedException("Highlight expression must select a member");
            }

            // Highlighting is inserted into the materialization chain
            if (searchRequest.Highlight == null)
            {
                searchRequest.Highlight = (Highlight)((ConstantExpression)configExpression).Value;
                materializer            = new HighlightElasticMaterializer(materializer);
            }

            if (Mapping.TryGetFieldName(SourceType, bodyExpression, out string fieldName))
            {
                searchRequest.Highlight.AddFields(fieldName);
            }

            return(Visit(source));
        }
Beispiel #6
0
 public FacetRebindCollectionResult(Expression expression, IEnumerable <IFacet> collected, ParameterExpression parameter, IElasticMaterializer materializer)
     : base(expression, collected, parameter)
 {
     Materializer = materializer;
 }
 public ElasticTranslateResult(SearchRequest searchRequest, IElasticMaterializer materializer)
 {
     this.searchRequest = searchRequest;
     this.materializer = materializer;
 }
        void CompleteFacetTranslation(FacetRebindCollectionResult aggregated)
        {
            Visit(aggregated.Expression);
            searchRequest.DocumentType = Mapping.GetDocumentType(SourceType);

            searchRequest.Facets = aggregated.Collected.ToList();
            searchRequest.SearchType = "count"; // We only want facets, not hits

            materializer = aggregated.Materializer;
        }
        Expression VisitFirstOrSingle(Expression source, Expression predicate, string methodName)
        {
            var single = methodName.StartsWith("Single", StringComparison.Ordinal);
            var orDefault = methodName.EndsWith("OrDefault", StringComparison.Ordinal);

            searchRequest.Size = single ? 2 : 1;
            finalItemType = source.Type;
            materializer = new OneHitElasticMaterializer(itemProjector ?? DefaultItemProjector, finalItemType, single, orDefault);

            return predicate != null
                ? VisitWhere(source, predicate)
                : Visit(source);
        }
        Expression VisitHighlight(Expression source, Expression highlightExpression, Expression configExpression)
        {
            var unaryExpression = highlightExpression as UnaryExpression;
            if (unaryExpression == null) throw new NotSupportedException("Highlight expression specify only one property");

            var lambdaExpression = unaryExpression.Operand as LambdaExpression;
            if (lambdaExpression == null) throw new NotSupportedException("Highlight expression must be lambda");

            var bodyExpression = lambdaExpression.Body as MemberExpression;
            if (bodyExpression == null) throw new NotSupportedException("Highlight expression must select a member");

            // Highlighting is inserted into the materialization chain
            if (searchRequest.Highlight == null)
            {
                searchRequest.Highlight = (Highlight)((ConstantExpression)configExpression).Value;
                materializer = new HighlightElasticMaterializer(materializer);
            }

            searchRequest.Highlight.AddFields(Mapping.GetFieldName(SourceType, bodyExpression));

            return Visit(source);
        }
 public ElasticTranslateResult(SearchRequest searchRequest, IElasticMaterializer materializer)
 {
     SearchRequest = searchRequest;
     Materializer  = materializer;
 }
Beispiel #12
0
 public HighlightElasticMaterializer(IElasticMaterializer previous) : base(previous)
 {
 }
 protected ChainMaterializer(IElasticMaterializer next)
 {
     Next = next;
 }
        private Expression VisitAny(Expression source, Expression predicate)
        {
            materializer = new AnyElasticMaterializer();
            searchRequest.SearchType = "count";
            searchRequest.Size = 1;

            return predicate != null
                ? VisitWhere(source, predicate)
                : Visit(source);
        }
 public HighlightElasticMaterializer(IElasticMaterializer previous)
     : base(previous)
 {
 }
 protected ChainMaterializer(IElasticMaterializer next)
 {
     Next = next;
 }
 Expression VisitCount(Expression source, Expression predicate)
 {
     materializer = new CountElasticMaterializer();
     searchRequest.SearchType = "count";
     return predicate != null
         ? VisitWhere(source, predicate)
         : Visit(source);
 }
 public ElasticTranslateResult(ElasticSearchRequest searchRequest, IElasticMaterializer materializer)
 {
     this.searchRequest = searchRequest;
     this.materializer  = materializer;
 }