Пример #1
0
 internal SuggestParametersPayload ToPayload(string searchText, string suggesterName) =>
 new SuggestParametersPayload()
 {
     Filter           = Filter,
     Fuzzy            = UseFuzzyMatching,
     HighlightPostTag = HighlightPostTag,
     HighlightPreTag  = HighlightPreTag,
     MinimumCoverage  = MinimumCoverage,
     OrderBy          = OrderBy.ToCommaSeparatedString(),
     Search           = searchText,
     SearchFields     = SearchFields.ToCommaSeparatedString(),
     Select           = (Select != null && Select.Any()) ? Select.ToCommaSeparatedString() : "*",
     SuggesterName    = suggesterName,
     Top = Top
 };
Пример #2
0
        private IEnumerable <QueryOption> GetAllOptions()
        {
            if (Filter != null)
            {
                yield return(new QueryOption("$filter", Uri.EscapeDataString(Filter)));
            }

            if (HighlightPreTag != null)
            {
                yield return(new QueryOption("highlightPreTag", Uri.EscapeDataString(HighlightPreTag)));
            }

            if (HighlightPostTag != null)
            {
                yield return(new QueryOption("highlightPostTag", Uri.EscapeDataString(HighlightPostTag)));
            }

            if (MinimumCoverage != null)
            {
                yield return(new QueryOption("minimumCoverage", MinimumCoverage.ToString()));
            }

            if (OrderBy.Any())
            {
                yield return(new QueryOption("$orderby", OrderBy));
            }

            if (SearchFields.Any())
            {
                yield return(new QueryOption("searchFields", SearchFields));
            }

            if (Select.Any())
            {
                yield return(new QueryOption("$select", Select));
            }
            else
            {
                yield return(new QueryOption("$select", "*"));
            }

            if (Top != null)
            {
                yield return(new QueryOption("$top", Top.ToString()));
            }

            yield return(new QueryOption("fuzzy", UseFuzzyMatching.ToString().ToLowerInvariant()));
        }
            protected virtual IEnumerable <string> GetParts()
            {
                if (Select.Any())
                {
                    yield return("$select=" + String.Join(",", Select));
                }

                if (Expand.Any())
                {
                    yield return("$expand=" + String.Join(",", Expand.Select(e => $"{e.PropertyName}({e})")));
                }

                if (Filter.Any())
                {
                    yield return("$filter=" + String.Join(" and ", Filter));
                }
            }
Пример #4
0
        /// <summary>
        /// Returns a <see cref="System.String" /> that represents this instance.
        /// </summary>
        /// <returns>A <see cref="System.String" /> that represents this instance.</returns>
        /// <exception cref="ArgumentException">Resource</exception>
        public override string ToString()
        {
            if (string.IsNullOrEmpty(ObjectStructureName))
            {
                throw new ArgumentException($"Required paramater '{nameof(ObjectStructureName)}' was not given.");
            }

            if (string.IsNullOrEmpty(Id))
            {
                throw new ArgumentException($"Required parameter '{nameof(Id)} was not given.");
            }

            var sb = new StringBuilder();

            sb.Append($"{ObjectStructureName}/{Id}?");

            if (Select != null && Select.Any())
            {
                var selectSb = new StringBuilder("oslc.select=");
                foreach (var att in Select)
                {
                    selectSb.Append($"{att},");
                }

                var selectStr = selectSb.ToString();
                if (selectStr.EndsWith(","))
                {
                    selectStr = selectStr.Remove(selectStr.Length - 1);
                }

                sb.Append(selectStr);
            }
            else
            {
                sb.Append("oslc.select=*");
            }

            if (UseLean)
            {
                sb.Append("&lean=1");
            }

            return(sb.ToString());
        }
Пример #5
0
        public Dictionary <string, string> GetPageHeader()
        {
            var dict = new Dictionary <string, string>();

            if (Filter.Any())
            {
                dict.Add("filter", Filter.GetQuery());
            }
            if (OrderBy.Any())
            {
                dict.Add("orderBy", OrderBy.GetQuery());
            }
            if (Select.Any())
            {
                dict.Add("select", Select.GetQuery());
            }
            if (Expand.Any())
            {
                dict.Add("expand", Expand.GetQuery());
            }

            return(dict);
        }
        private IEnumerable <QueryOption> GetAllOptions()
        {
            yield return(new QueryOption("$count", IncludeTotalResultCount.ToString().ToLowerInvariant()));

            foreach (string facetExpr in Facets)
            {
                yield return(new QueryOption("facet", Uri.EscapeDataString(facetExpr)));
            }

            if (Filter != null)
            {
                yield return(new QueryOption("$filter", Uri.EscapeDataString(Filter)));
            }

            if (HighlightFields.Any())
            {
                yield return(new QueryOption("highlight", HighlightFields));
            }

            if (HighlightPreTag != null)
            {
                yield return(new QueryOption("highlightPreTag", Uri.EscapeDataString(HighlightPreTag)));
            }

            if (HighlightPostTag != null)
            {
                yield return(new QueryOption("highlightPostTag", Uri.EscapeDataString(HighlightPostTag)));
            }

            if (MinimumCoverage != null)
            {
                yield return(new QueryOption("minimumCoverage", MinimumCoverage.ToString()));
            }

            if (OrderBy.Any())
            {
                yield return(new QueryOption("$orderby", OrderBy));
            }

            foreach (string scoringParameterExpr in ScoringParameters)
            {
                yield return(new QueryOption("scoringParameter", scoringParameterExpr));
            }

            if (ScoringProfile != null)
            {
                yield return(new QueryOption("scoringProfile", ScoringProfile));
            }

            if (SearchFields.Any())
            {
                yield return(new QueryOption("searchFields", SearchFields));
            }

            yield return(new QueryOption("searchMode", SearchIndexClient.SearchModeToString(SearchMode)));

            if (Select.Any())
            {
                yield return(new QueryOption("$select", Select));
            }

            if (Skip != null)
            {
                yield return(new QueryOption("$skip", Skip.ToString()));
            }

            if (Top != null)
            {
                yield return(new QueryOption("$top", Top.ToString()));
            }
        }
Пример #7
0
        /// <summary>
        /// Returns a <see cref="System.String" /> that represents this instance.
        /// </summary>
        /// <returns>A <see cref="System.String" /> that represents this instance.</returns>
        /// <exception cref="ArgumentException">Resource</exception>
        public override string ToString()
        {
            if (string.IsNullOrEmpty(ObjectStructureName))
            {
                throw new ArgumentException($"Required paramater '{nameof(ObjectStructureName)}' was not given.");
            }

            var sb = new StringBuilder();

            sb.Append($"{ObjectStructureName}?");

            if (Select != null && Select.Any())
            {
                var selectSb = new StringBuilder("oslc.select=");
                foreach (var att in Select)
                {
                    selectSb.Append($"{att}{SELECT_SEPERATOR}");
                }

                var selectStr = selectSb.ToString();
                if (selectStr.EndsWith(SELECT_SEPERATOR))
                {
                    selectStr = selectStr.Remove(selectStr.Length - SELECT_SEPERATOR.Length);
                }

                sb.Append(selectStr);
            }
            else if (!IsCreate)
            {
                sb.Append("oslc.select=*");
            }

            if (!string.IsNullOrEmpty(SavedQuery))
            {
                sb.Append($"&savedQuery={SavedQuery}");
            }

            if (Where.Any() || WhereIn.Any())
            {
                var whereSb = new StringBuilder("&oslc.where=");
                foreach (var what in Where)
                {
                    whereSb.Append($"{what}{WHERE_SEPERATOR}");
                }

                foreach (var whatIn in WhereIn)
                {
                    var valueList = whatIn.Value.Select(v => $"\"{v}\"").ToList();
                    whereSb.Append($"{whatIn.Key} in [{string.Join(",", valueList)}]{WHERE_SEPERATOR}");
                }

                var whereStr = whereSb.ToString();
                if (whereStr.EndsWith(WHERE_SEPERATOR))
                {
                    whereStr = whereStr.Remove(whereStr.Length - WHERE_SEPERATOR.Length);
                }

                sb.Append(whereStr);
            }

            if (OrderBy != null)
            {
                sb.Append("&oslc.orderBy=");

                sb.Append(OrderByDescending ? "-" : "%2B");

                sb.Append(OrderBy);
            }

            if (PageSize != null && PageSize > 0)
            {
                sb.Append($"&oslc.pageSize={PageSize}");

                if (PageNumber != null && PageNumber > 1)
                {
                    sb.Append($"&pageno={PageNumber}");
                }
            }

            if (UseLean)
            {
                sb.Append("&lean=1");
            }

            if (UseOr)
            {
                sb.Append("&opmodeor=1");
            }

            return(sb.ToString());
        }
Пример #8
0
        /// <summary>
        /// Returns a <see cref="System.String" /> that represents this instance.
        /// </summary>
        /// <returns>
        /// A <see cref="System.String" /> that represents this instance.
        /// </returns>
        /// <exception cref="NotImplementedException"></exception>
        public override string ToString()
        {
            if (string.IsNullOrEmpty(ObjectStructureName))
            {
                throw new ArgumentException($"Required paramater '{nameof(ObjectStructureName)}' was not given.");
            }

            var sb = new StringBuilder();

            sb.Append($"{ObjectStructureName}?");

            if (Select != null && Select.Any())
            {
                var selectSb = new StringBuilder("oslc.select=");
                foreach (var att in Select)
                {
                    selectSb.Append($"{att}{SELECT_SEPERATOR}");
                }

                var selectStr = selectSb.ToString();
                if (selectStr.EndsWith(SELECT_SEPERATOR))
                {
                    selectStr = selectStr.Remove(selectStr.Length - SELECT_SEPERATOR.Length);
                }

                sb.Append(selectStr);
            }
            else
            {
                sb.Append("oslc.select=*");
            }

            if (SearchAttributes.Any() && !string.IsNullOrEmpty(SearchTerm))
            {
                var searchSb = new StringBuilder("&searchAttributes=");
                foreach (var attribute in SearchAttributes)
                {
                    searchSb.Append($"{attribute}{SELECT_SEPERATOR}");
                }

                var searchStr = searchSb.ToString();
                if (searchStr.EndsWith(SELECT_SEPERATOR))
                {
                    searchStr = searchStr.Remove(searchStr.Length - SELECT_SEPERATOR.Length);
                }

                sb.Append(searchStr);
                sb.Append($"&oslc.searchTerms=\"{SearchTerm}\"");
            }

            if (OrderBy != null)
            {
                sb.Append("&orderBy=");

                sb.Append(OrderByDescending ? "-" : "%2B");

                sb.Append(OrderBy);
            }

            if (PageSize != null && PageSize > 0)
            {
                sb.Append($"&oslc.pageSize={PageSize}");

                if (PageNumber != null && PageNumber > 1)
                {
                    sb.Append($"&pageno={PageNumber}");
                }
            }

            if (UseLean)
            {
                sb.Append("&lean=1");
            }

            return(sb.ToString());
        }
Пример #9
0
        private IEnumerable <QueryOption> GetAllOptions()
        {
            yield return(new QueryOption("$count", IncludeTotalResultCount.ToString().ToLowerInvariant()));

            foreach (string facetExpr in Facets ?? Empty)
            {
                yield return(new QueryOption("facet", Uri.EscapeDataString(facetExpr)));
            }

            if (Filter != null)
            {
                yield return(new QueryOption("$filter", Uri.EscapeDataString(Filter)));
            }

            if (HighlightFields != null && HighlightFields.Any())
            {
                yield return(new QueryOption("highlight", HighlightFields));
            }

            if (HighlightPreTag != null)
            {
                yield return(new QueryOption("highlightPreTag", Uri.EscapeDataString(HighlightPreTag)));
            }

            if (HighlightPostTag != null)
            {
                yield return(new QueryOption("highlightPostTag", Uri.EscapeDataString(HighlightPostTag)));
            }

            if (MinimumCoverage != null)
            {
                yield return(new QueryOption("minimumCoverage", MinimumCoverage.ToString()));
            }

            if (OrderBy != null && OrderBy.Any())
            {
                yield return(new QueryOption("$orderby", OrderBy));
            }

            yield return(new QueryOption("queryType", (QueryType == Models.QueryType.Simple) ? "simple" : "full"));

            foreach (string scoringParameterExpr in ScoringParameterStrings)
            {
                yield return(new QueryOption("scoringParameter", scoringParameterExpr));
            }

            if (ScoringProfile != null)
            {
                yield return(new QueryOption("scoringProfile", ScoringProfile));
            }

            if (SearchFields != null && SearchFields.Any())
            {
                yield return(new QueryOption("searchFields", SearchFields));
            }

            yield return(new QueryOption("searchMode", (SearchMode == Models.SearchMode.Any) ? "any" : "all"));

            if (Select != null && Select.Any())
            {
                yield return(new QueryOption("$select", Select));
            }

            if (Skip != null)
            {
                yield return(new QueryOption("$skip", Skip.ToString()));
            }

            if (Top != null)
            {
                yield return(new QueryOption("$top", Top.ToString()));
            }
        }