Example #1
0
        public static FacetQuery Create(string indexName, IndexQueryBase query, string facetSetupDoc, List <Facet> facets, int start, int?pageSize)
        {
            var result = new FacetQuery
            {
                IndexName                     = indexName,
                CutoffEtag                    = query.CutoffEtag,
                DefaultField                  = query.DefaultField,
                DefaultOperator               = query.DefaultOperator,
                FieldsToFetch                 = query.FieldsToFetch,
                IsDistinct                    = query.IsDistinct,
                Query                         = query.Query,
                WaitForNonStaleResults        = query.WaitForNonStaleResults,
                WaitForNonStaleResultsAsOfNow = query.WaitForNonStaleResultsAsOfNow,
                WaitForNonStaleResultsTimeout = query.WaitForNonStaleResultsTimeout,
                Start                         = start,
                FacetSetupDoc                 = facetSetupDoc,
                Facets                        = facets
            };

            if (pageSize.HasValue)
            {
                result.PageSize = pageSize.Value;
            }

            return(result);
        }
Example #2
0
        public static FacetQuery Parse(IQueryCollection query, int start, int pageSize)
        {
            var result = new FacetQuery
            {
                Start    = start,
                PageSize = pageSize
            };

            StringValues values;

            if (query.TryGetValue("facetDoc", out values))
            {
                result.FacetSetupDoc = values.First();
            }

            if (query.TryGetValue("distinct", out values))
            {
                result.IsDistinct = bool.Parse(values.First());
            }

            if (query.TryGetValue("operator", out values))
            {
                result.DefaultOperator = "And".Equals(values.First(), StringComparison.OrdinalIgnoreCase) ? QueryOperator.And : QueryOperator.Or;
            }

            if (query.TryGetValue("defaultField", out values))
            {
                result.DefaultField = values.First();
            }

            if (query.TryGetValue("query", out values))
            {
                result.Query = values.First();
            }

            if (query.TryGetValue("fetch", out values))
            {
                result.FieldsToFetch = values.ToArray();
            }

            if (query.TryGetValue("cutOffEtag", out values))
            {
                result.CutoffEtag = long.Parse(values.First());
            }

            if (query.TryGetValue("waitForNonStaleResultsAsOfNow", out values))
            {
                result.WaitForNonStaleResultsAsOfNow = bool.Parse(values.First());
            }

            if (query.TryGetValue("waitForNonStaleResultsTimeout", out values))
            {
                result.WaitForNonStaleResultsTimeout = TimeSpan.Parse(values.First());
            }

            return(result);
        }