예제 #1
0
 /// <summary>
 /// Builds the search query with search aggregations enabled.
 /// </summary>
 /// <remarks>Indicates that we will return search aggregations when we perform searches.</remarks>
 /// <returns>QueryStepBuilder.</returns>
 public QueryStepBuilder <TSource, SearchModel> BuildWithAggregate()
 {
     // We just need this key to indicate we are enabling aggregating, and do not need a value.
     _queryStepBuilder.AddStepBagItem(SearchConstants.EnableAggregate, null);
     _queryStepBuilder.WithProperty(x => x.Filters);
     return(Build());
 }
        public QueryStepBuilder <TSource, SearchModel> BeginSearch(params Type[] searchTypes)
        {
            var step = new QueryStepBuilder <TSource, SearchModel>(this);

            step.WithProperty(x => x.SearchText);
            step.AddStepBagItem(SearchConstants.QueryTypes, searchTypes);
            step.AddStepBagItem(SearchConstants.QueryName, _queryBuilder.QueryName);
            return(step);
        }
        /// <summary>
        /// Creates a new instance of SearchQueryBuilder.
        /// </summary>
        /// <typeparam name="TSource">Search source type.</typeparam>
        /// <param name="qb">QueryBuilder instance.</param>
        /// <returns>QueryStepBuilder.</returns>
        private static QueryStepBuilder <TSource, SearchModel> Create <TSource>(QueryParameterBuilder <TSource> qb)
        {
            var step = new QueryStepBuilder <TSource, SearchModel>(qb);

            step.DisableConnectionEdgeCheck();
            step.OverrideRepositoryTypeWith <SearchResult>();
            step.AddStepBagItem(SearchConstants.QueryName, qb.GetQueryBuilderQueryName());
            step.WithProperty(x => x.SearchText);
            step.AddQueryExecutionContextInterceptor(ctx =>
            {
                // This step is for backwards compatibility.
                var searchResults = ctx.GetQueryResults <SearchResult>();

                var list = new List <SearchResultModel>();

                searchResults.ForEach(sr => list.AddRange(sr.Values));

                ctx.SystemItems[typeof(SearchResult).FullName] = searchResults;

                ctx.SetQueryResult(list.Select(x => (object)x).ToList());
            });
            return(step);
        }