Ejemplo n.º 1
0
		public FacetResults GetFacets(string index, IndexQuery indexQuery, List<Facet> facets, int start = 0, int? pageSize = null)
		{
			var sp = Stopwatch.StartNew();
			var results = new FacetResults();
			var defaultFacets = new Dictionary<string, Facet>();
			var rangeFacets = new Dictionary<string, List<ParsedRange>>();

			var viewGenerator = database.IndexDefinitionStorage.GetViewGenerator(index);
			Index.AssertQueryDoesNotContainFieldsThatAreNotIndexed(indexQuery, viewGenerator);

			foreach (var facet in facets)
			{
				var key = string.IsNullOrWhiteSpace(facet.DisplayName) ? facet.Name : facet.DisplayName;

				defaultFacets[key] = facet;
				if (facet.Aggregation != FacetAggregation.Count && facet.Aggregation != FacetAggregation.None)
				{
					if (string.IsNullOrEmpty(facet.AggregationField))
						throw new InvalidOperationException("Facet " + facet.Name + " cannot have aggregation set to " +
															facet.Aggregation + " without having a value in AggregationField");

					if (facet.AggregationField.EndsWith("_Range") == false)
					{
						if (QueryForFacets.IsAggregationTypeNumerical(facet.AggregationType))
							facet.AggregationField = facet.AggregationField + "_Range";
					}

				}


				switch (facet.Mode)
				{
					case FacetMode.Default:
						results.Results[key] = new FacetResult();
						break;
					case FacetMode.Ranges:
						rangeFacets[key] = facet.Ranges.Select(range => ParseRange(facet.Name, range)).ToList();
						results.Results[key] = new FacetResult
						{
							Values = facet.Ranges.Select(range => new FacetValue
							{
								Range = range,
							}).ToList()
						};

						break;
					default:
						throw new ArgumentException(string.Format("Could not understand '{0}'", facet.Mode));
				}
			}

			var queryForFacets = new QueryForFacets(database, index, defaultFacets, rangeFacets, indexQuery, results, start, pageSize);
			queryForFacets.Execute();
			results.Duration = sp.Elapsed;
			return results;
		}
Ejemplo n.º 2
0
        public FacetResults GetFacets(string index, IndexQuery indexQuery, List <Facet> facets, int start = 0, int?pageSize = null)
        {
            var results       = new FacetResults();
            var defaultFacets = new Dictionary <string, Facet>();
            var rangeFacets   = new Dictionary <string, List <ParsedRange> >();

            foreach (var facet in facets)
            {
                var key = string.IsNullOrWhiteSpace(facet.DisplayName) ? facet.Name : facet.DisplayName;

                defaultFacets[key] = facet;
                if (facet.Aggregation != FacetAggregation.Count && facet.Aggregation != FacetAggregation.None)
                {
                    if (string.IsNullOrEmpty(facet.AggregationField))
                    {
                        throw new InvalidOperationException("Facet " + facet.Name + " cannot have aggregation set to " +
                                                            facet.Aggregation + " without having a value in AggregationField");
                    }

                    if (facet.AggregationField.EndsWith("_Range") == false)
                    {
                        facet.AggregationField = facet.AggregationField + "_Range";
                    }
                }


                switch (facet.Mode)
                {
                case FacetMode.Default:
                    results.Results[key] = new FacetResult();
                    break;

                case FacetMode.Ranges:
                    rangeFacets[key]     = facet.Ranges.Select(range => ParseRange(facet.Name, range)).ToList();
                    results.Results[key] = new FacetResult
                    {
                        Values = facet.Ranges.Select(range => new FacetValue
                        {
                            Range = range,
                        }).ToList()
                    };

                    break;

                default:
                    throw new ArgumentException(string.Format("Could not understand '{0}'", facet.Mode));
                }
            }

            var queryForFacets = new QueryForFacets(database, index, defaultFacets, rangeFacets, indexQuery, results, start, pageSize);

            queryForFacets.Execute();

            return(results);
        }
Ejemplo n.º 3
0
        public FacetResults GetFacets(string index, IndexQuery indexQuery, string facetSetupDoc, int start = 0, int?pageSize = null)
        {
            var facetSetup = database.Get(facetSetupDoc, null);

            if (facetSetup == null)
            {
                throw new InvalidOperationException("Could not find facets document: " + facetSetupDoc);
            }

            var facets = facetSetup.DataAsJson.JsonDeserialization <FacetSetup>().Facets;

            var results       = new FacetResults();
            var defaultFacets = new Dictionary <string, Facet>();
            var rangeFacets   = new Dictionary <string, List <ParsedRange> >();

            foreach (var facet in facets)
            {
                switch (facet.Mode)
                {
                case FacetMode.Default:
                    //Remember the facet, so we can run them all under one query
                    defaultFacets[facet.Name]   = facet;
                    results.Results[facet.Name] = new FacetResult();
                    break;

                case FacetMode.Ranges:
                    rangeFacets[facet.Name]     = facet.Ranges.Select(range => ParseRange(facet.Name, range)).ToList();
                    results.Results[facet.Name] = new FacetResult
                    {
                        Values = facet.Ranges.Select(range => new FacetValue
                        {
                            Range = range,
                        }).ToList()
                    };

                    break;

                default:
                    throw new ArgumentException(string.Format("Could not understand '{0}'", facet.Mode));
                }
            }

            var queryForFacets = new QueryForFacets(database, index, defaultFacets, rangeFacets, indexQuery, results, start, pageSize);

            queryForFacets.Execute();

            return(results);
        }
Ejemplo n.º 4
0
		public FacetResults GetFacets(string index, IndexQuery indexQuery, string facetSetupDoc, int start = 0, int? pageSize = null)
		{
			var facetSetup = database.Get(facetSetupDoc, null);
			if (facetSetup == null)
				throw new InvalidOperationException("Could not find facets document: " + facetSetupDoc);

			var facets = facetSetup.DataAsJson.JsonDeserialization<FacetSetup>().Facets;

			var results = new FacetResults();
			var defaultFacets = new Dictionary<string, Facet>();
			var rangeFacets = new Dictionary<string, List<ParsedRange>>();

			foreach (var facet in facets)
			{
				switch (facet.Mode)
				{
					case FacetMode.Default:
						//Remember the facet, so we can run them all under one query
						defaultFacets[facet.Name] = facet;
						results.Results[facet.Name] = new FacetResult();
						break;
					case FacetMode.Ranges:
						rangeFacets[facet.Name] = facet.Ranges.Select(range => ParseRange(facet.Name, range)).ToList();
						results.Results[facet.Name] = new FacetResult
						{
							Values = facet.Ranges.Select(range => new FacetValue
							{
								Range = range,
							}).ToList()
						};

						break;
					default:
						throw new ArgumentException(string.Format("Could not understand '{0}'", facet.Mode));
				}
			}

			var queryForFacets = new QueryForFacets(database, index, defaultFacets, rangeFacets, indexQuery, results, start, pageSize);
			queryForFacets.Execute();

			return results;
		}
Ejemplo n.º 5
0
        public FacetResults GetFacets(string index, IndexQuery indexQuery, List <Facet> facets, int start = 0, int?pageSize = null)
        {
            var sp            = Stopwatch.StartNew();
            var results       = new FacetResults();
            var defaultFacets = new Dictionary <string, Facet>();
            var rangeFacets   = new Dictionary <string, List <ParsedRange> >();

            var viewGenerator = database.IndexDefinitionStorage.GetViewGenerator(index);

            if (viewGenerator == null)
            {
                throw new IndexDoesNotExistsException("Index " + index + " does not exists");
            }
            Index.AssertQueryDoesNotContainFieldsThatAreNotIndexed(indexQuery, viewGenerator);

            foreach (var facet in facets)
            {
                var key = string.IsNullOrWhiteSpace(facet.DisplayName) ? facet.Name : facet.DisplayName;

                defaultFacets[key] = facet;
                if (facet.Aggregation != FacetAggregation.Count && facet.Aggregation != FacetAggregation.None)
                {
                    if (string.IsNullOrEmpty(facet.AggregationField))
                    {
                        throw new InvalidOperationException("Facet " + facet.Name + " cannot have aggregation set to " +
                                                            facet.Aggregation + " without having a value in AggregationField");
                    }

                    if (facet.AggregationField.EndsWith("_Range") == false)
                    {
                        facet.AggregationField = facet.AggregationField + "_Range";
                    }
                }


                switch (facet.Mode)
                {
                case FacetMode.Default:
                    results.Results[key] = new FacetResult();
                    break;

                case FacetMode.Ranges:
                    rangeFacets[key]     = facet.Ranges.Select(range => ParseRange(facet.Name, range)).ToList();
                    results.Results[key] = new FacetResult
                    {
                        Values = facet.Ranges.Select(range => new FacetValue
                        {
                            Range = range,
                        }).ToList()
                    };

                    break;

                default:
                    throw new ArgumentException(string.Format("Could not understand '{0}'", facet.Mode));
                }
            }

            var queryForFacets = new QueryForFacets(database, index, defaultFacets, rangeFacets, indexQuery, results, start, pageSize);

            queryForFacets.Execute();
            results.Duration = sp.Elapsed;
            return(results);
        }