Esempio n. 1
0
        internal static FacetRebindCollectionResult Rebind(IElasticMapping mapping, Type sourceType, Expression expression)
        {
            Argument.EnsureNotNull(nameof(mapping), mapping);
            Argument.EnsureNotNull(nameof(expression), expression);

            var visitor           = new FacetExpressionVisitor(mapping, sourceType);
            var visitedExpression = visitor.Visit(expression);
            var facets            = new HashSet <IFacet>(visitor.GetFacets());
            var materializer      = GetFacetMaterializer(visitor.selectProjection, visitor.groupBy);

            return(new FacetRebindCollectionResult(visitedExpression, facets, visitor.bindingParameter, materializer));
        }
        ElasticTranslateResult Translate(Expression e)
        {
            var evaluated  = PartialEvaluator.Evaluate(e);
            var aggregated = FacetExpressionVisitor.Rebind(Mapping, SourceType, evaluated);

            if (aggregated.Collected.Count > 0)
            {
                CompleteFacetTranslation(aggregated);
            }
            else
            {
                CompleteHitTranslation(evaluated);
            }

            searchRequest.Query  = QueryCriteriaRewriter.Compensate(searchRequest.Query);
            searchRequest.Filter = ConstantCriteriaFilterReducer.Reduce(searchRequest.Filter);
            ApplyTypeSelectionCriteria();

            return(new ElasticTranslateResult(searchRequest, materializer));
        }