Example #1
0
 internal SearchRequest ToRequest(string searchText) =>
 new SearchRequest()
 {
     IncludeTotalResultCount = IncludeTotalResultCount,
     Facets            = Facets ?? Empty,
     Filter            = Filter,
     HighlightFields   = HighlightFields.ToCommaSeparatedString(),
     HighlightPostTag  = HighlightPostTag,
     HighlightPreTag   = HighlightPreTag,
     MinimumCoverage   = MinimumCoverage,
     OrderBy           = OrderBy.ToCommaSeparatedString(),
     QueryType         = QueryType,
     ScoringParameters = ScoringParameters?.Select(p => p.ToString())?.ToList() ?? Empty,
     ScoringProfile    = ScoringProfile,
     SearchText        = searchText,
     SearchFields      = SearchFields.ToCommaSeparatedString(),
     SearchMode        = SearchMode,
     Select            = Select.ToCommaSeparatedString(),
     Skip = Skip,
     Top  = Top
 };
 internal SearchParametersPayload ToPayload(string searchText) =>
 new SearchParametersPayload()
 {
     Count             = IncludeTotalResultCount,
     Facets            = Facets ?? Empty,
     Filter            = Filter,
     Highlight         = HighlightFields.ToCommaSeparatedString(),
     HighlightPostTag  = HighlightPostTag,
     HighlightPreTag   = HighlightPreTag,
     MinimumCoverage   = MinimumCoverage,
     OrderBy           = OrderBy.ToCommaSeparatedString(),
     QueryType         = QueryType,
     ScoringParameters = ScoringParameterStrings,
     ScoringProfile    = ScoringProfile,
     Search            = searchText,
     SearchFields      = SearchFields.ToCommaSeparatedString(),
     SearchMode        = SearchMode,
     Select            = Select.ToCommaSeparatedString(),
     Skip = Skip,
     Top  = Top
 };
        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()));
            }
        }
        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()));
            }
        }