Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 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);
            }
        }
Ejemplo n.º 3
0
        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));
        }
Ejemplo n.º 4
0
        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());
        }
Ejemplo n.º 5
0
        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));
        }
Ejemplo n.º 6
0
 public FacetRebindCollectionResult(Expression expression, IEnumerable <IFacet> collected, ParameterExpression parameter, IElasticMaterializer materializer)
     : base(expression, collected, parameter)
 {
     Materializer = materializer;
 }
Ejemplo n.º 7
0
 public ElasticTranslateResult(SearchRequest searchRequest, IElasticMaterializer materializer)
 {
     this.searchRequest = searchRequest;
     this.materializer = materializer;
 }
Ejemplo n.º 8
0
        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;
        }
Ejemplo n.º 9
0
        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);
        }
Ejemplo n.º 10
0
        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);
        }
Ejemplo n.º 11
0
 public ElasticTranslateResult(SearchRequest searchRequest, IElasticMaterializer materializer)
 {
     SearchRequest = searchRequest;
     Materializer  = materializer;
 }
Ejemplo n.º 12
0
 public HighlightElasticMaterializer(IElasticMaterializer previous) : base(previous)
 {
 }
Ejemplo n.º 13
0
 protected ChainMaterializer(IElasticMaterializer next)
 {
     Next = next;
 }
Ejemplo n.º 14
0
        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;
 }
Ejemplo n.º 17
0
 Expression VisitCount(Expression source, Expression predicate)
 {
     materializer = new CountElasticMaterializer();
     searchRequest.SearchType = "count";
     return predicate != null
         ? VisitWhere(source, predicate)
         : Visit(source);
 }
Ejemplo n.º 18
0
 public ElasticTranslateResult(ElasticSearchRequest searchRequest, IElasticMaterializer materializer)
 {
     this.searchRequest = searchRequest;
     this.materializer  = materializer;
 }