示例#1
0
        public FacetContent Load(FacetsConfig2 facetsConfig)
        {
            /* Compile Interval Sql and number of categories */
            var intervalInfo = CompileIntervalQuery(facetsConfig, facetsConfig.TargetCode);

            /* Compute (filtered) category counts */
            var categoryCounts = QueryCategoryCounts(facetsConfig, intervalInfo.Query);

            /* Compile counts for full set of categories */
            var outerCategoryCounts = QueryOuterCategoryCounts(intervalInfo.Query, categoryCounts.CategoryCounts).ToList();

            /* Collect user picks */
            var userPicks = facetsConfig.CollectUserPicks(facetsConfig.TargetCode);

            var facetContent = new FacetContent
            {
                FacetsConfig = facetsConfig,
                Items        = outerCategoryCounts.Where(z => z.Count != null).ToList(), /* add empty categories then remove, hmmm...? */
                Distribution = categoryCounts.CategoryCounts,
                IntervalInfo = intervalInfo,
                SqlQuery     = categoryCounts.SqlQuery,
                Picks        = userPicks ?? new Dictionary <string, FacetsConfig2.UserPickData>()
            };

            return(facetContent);
        }
        /// <summary>
        /// Removes invalid selections e.g. hidden selections still being sent from the client.
        /// The client keep them since they can be visible when the filters changes.
        /// This is only applicable for discrete facets (range facet selection are always visible)
        /// </summary>
        /// <param name="facetsConfig"></param>
        /// <returns></returns>
        public FacetsConfig2 Update(FacetsConfig2 facetsConfig)
        {
            foreach (string facetCode in facetsConfig.GetFacetCodes())
            {
                var config = facetsConfig.GetConfig(facetCode);

                if (config.Facet.FacetTypeId != EFacetType.Discrete || config.Picks.Count == 0)
                {
                    continue;
                }

                if (!config.HasPicks())
                {
                    continue;
                }

                config.Picks = QueryProxy.QueryRows(
                    PicksCompiler.Compile(
                        QuerySetupBuilder.Build(facetsConfig, config.Facet, null, null),
                        config.GetIntegerPickValues()
                        ),
                    x => new FacetConfigPick(EPickType.discrete, x.GetString(0), x.GetString(1))
                    );
            }
            return(facetsConfig);
        }
示例#3
0
        public virtual CategoryCountData Load(string facetCode, FacetsConfig2 facetsConfig, string intervalQuery = null)
        {
            var sqlQuery       = Compile(Facets.GetByCode(facetCode), facetsConfig, intervalQuery);
            var categoryCounts = Query(sqlQuery).ToDictionary(z => z.Category ?? "(null)");

            return(new CategoryCountData {
                SqlQuery = sqlQuery,
                CategoryCounts = categoryCounts
            });
        }
示例#4
0
        protected override FacetContent.IntervalQueryInfo CompileIntervalQuery(FacetsConfig2 facetsConfig, string facetCode, int count = 0)
        {
            var querySetup = QuerySetupBuilder.Build(facetsConfig, facetsConfig.TargetFacet, null, null);
            var sql        = SqlCompiler.Compile(querySetup, facetsConfig.TargetFacet, facetsConfig.GetTargetTextFilter());

            return(new FacetContent.IntervalQueryInfo {
                Count = 1,
                Query = sql
            });
        }
 protected override string Compile(Facet facet, FacetsConfig2 facetsConfig, string intervalQuery)
 => RangeCountSqlCompiler.Compile(
     QuerySetupBuilder.Build(
         facetsConfig,
         facet,
         CountTables,
         facetsConfig.GetFacetCodes()
         ),
     facet,
     intervalQuery,
     Config.CountColumn
     );
        protected override string Compile(Facet facet, FacetsConfig2 facetsConfig, string payload)
        {
            // FIXME: Fix confusing args, when does facet differ from targetFacet?
            var aggregateFacet = Facets.Get(facet.AggregateFacetId);
            var targetFacet    = Facets.GetByCode(facetsConfig.TargetCode);
            var tableNames     = GetTables(facetsConfig, targetFacet, aggregateFacet);
            var facetCodes     = facetsConfig.GetFacetCodes();

            facetCodes.InsertAt(targetFacet.FacetCode, aggregateFacet.FacetCode);

            var querySetup = QuerySetupBuilder.Build(facetsConfig, aggregateFacet, tableNames, facetCodes);
            var sql        = CountSqlCompiler.Compile(querySetup, targetFacet, aggregateFacet, facet.AggregateType ?? "count");

            return(sql);
        }
示例#7
0
        protected override FacetContent.IntervalQueryInfo CompileIntervalQuery(FacetsConfig2 facetsConfig, string facetCode, int default_interval_count = 120)
        {
            var facetConfig = facetsConfig.GetConfig(facetCode);
            var fullExtent  = OuterBoundExtentService.GetExtent(facetConfig, default_interval_count);
            var pickExtent  = GetPickExtent(facetConfig, default_interval_count) ?? fullExtent;

            var(lower, upper, interval_count) = (pickExtent.Lower, pickExtent.Upper, pickExtent.Count);

            int interval = Math.Max((int)Math.Floor((upper - lower) / interval_count), 1);

            string sql = RangeIntervalSqlCompiler.Compile(interval, (int)lower, (int)upper, interval_count);

            return(new RangeIntervalQueryInfo
            {
                Count = interval,
                Query = sql,
                FullExtent = fullExtent
            });
        }
示例#8
0
        private CategoryCountService.CategoryCountData QueryCategoryCounts(FacetsConfig2 facetsConfig, string intervalQuery)
        {
            var categoryCounts = CategoryCountService.Load(facetsConfig.TargetCode, facetsConfig, intervalQuery);

            return(categoryCounts);
        }
示例#9
0
 protected virtual IntervalQueryInfo CompileIntervalQuery(FacetsConfig2 facetsConfig, string facetCode, int interval = 120) => new IntervalQueryInfo();
示例#10
0
 protected virtual string Compile(Facet facet, FacetsConfig2 facetsConfig, string intervalQuery) => throw new NotSupportedException();
 private List <string> GetTables(FacetsConfig2 facetsConfig, Facet targetFacet, Facet computeFacet)
 {
     return(targetFacet.GetResolvedTableNames()
            .Union(computeFacet.GetResolvedTableNames())
            .Distinct().ToList());
 }