Пример #1
0
        protected virtual IndexQuery GetIndexQuery(int maxPageSize)
        {
            var query = new IndexQuery
            {
                Query  = GetQueryStringValue("query") ?? queryFromPostRequest ?? "",
                Start  = GetStart(),
                Cutoff = GetCutOff(),
                WaitForNonStaleResultsAsOfNow = GetWaitForNonStaleResultsAsOfNow(),
                CutoffEtag    = GetCutOffEtag(),
                PageSize      = GetPageSize(maxPageSize),
                FieldsToFetch = GetQueryStringValues("fetch"),
                DefaultField  = GetQueryStringValue("defaultField"),

                DefaultOperator =
                    string.Equals(GetQueryStringValue("operator"), "AND", StringComparison.OrdinalIgnoreCase) ?
                    QueryOperator.And :
                    QueryOperator.Or,

                SortedFields = EnumerableExtension.EmptyIfNull(GetQueryStringValues("sort"))
                               .Select(x => new SortedField(x))
                               .ToArray(),
                HighlightedFields     = GetHighlightedFields().ToArray(),
                HighlighterPreTags    = GetQueryStringValues("preTags"),
                HighlighterPostTags   = GetQueryStringValues("postTags"),
                ResultsTransformer    = GetQueryStringValue("resultsTransformer"),
                TransformerParameters = ExtractTransformerParameters(),
                ExplainScores         = GetExplainScores(),
                SortHints             = GetSortHints(),
                IsDistinct            = IsDistinct()
            };

            var  allowMultipleIndexEntriesForSameDocumentToResultTransformer = GetQueryStringValue("allowMultipleIndexEntriesForSameDocumentToResultTransformer");
            bool allowMultiple;

            if (string.IsNullOrEmpty(allowMultipleIndexEntriesForSameDocumentToResultTransformer) == false && bool.TryParse(allowMultipleIndexEntriesForSameDocumentToResultTransformer, out allowMultiple))
            {
                query.AllowMultipleIndexEntriesForSameDocumentToResultTransformer = allowMultiple;
            }

            if (query.WaitForNonStaleResultsAsOfNow)
            {
                query.Cutoff = SystemTime.UtcNow;
            }

            var  showTimingsAsString = GetQueryStringValue("showTimings");
            bool showTimings;

            if (string.IsNullOrEmpty(showTimingsAsString) == false && bool.TryParse(showTimingsAsString, out showTimings) && showTimings)
            {
                query.ShowTimings = true;
            }

            var          spatialFieldName = GetQueryStringValue("spatialField") ?? Constants.DefaultSpatialFieldName;
            var          queryShape       = GetQueryStringValue("queryShape");
            SpatialUnits units;
            var          unitsSpecified = Enum.TryParse(GetQueryStringValue("spatialUnits"), out units);
            double       distanceErrorPct;

            if (!double.TryParse(GetQueryStringValue("distErrPrc"), NumberStyles.Any, CultureInfo.InvariantCulture, out distanceErrorPct))
            {
                distanceErrorPct = Constants.DefaultSpatialDistanceErrorPct;
            }
            SpatialRelation spatialRelation;

            if (Enum.TryParse(GetQueryStringValue("spatialRelation"), false, out spatialRelation) && !string.IsNullOrWhiteSpace(queryShape))
            {
                return(new SpatialIndexQuery(query)
                {
                    SpatialFieldName = spatialFieldName,
                    QueryShape = queryShape,
                    RadiusUnitOverride = unitsSpecified ? units : (SpatialUnits?)null,
                    SpatialRelation = spatialRelation,
                    DistanceErrorPercentage = distanceErrorPct,
                });
            }

            return(query);
        }