示例#1
0
        private static SearchParameters BuildParameters(SearchQueryBuilder queryBuilder)
        {
            SearchParameters parameters = new SearchParameters
            {
                Top        = queryBuilder.HitsPerPage,
                Skip       = queryBuilder.PageNumber * queryBuilder.HitsPerPage,
                SearchMode = queryBuilder.SearchModeParam,
                QueryType  = queryBuilder.QueryTypeParam
            };

            if (queryBuilder.ScoreProfile != null)
            {
                parameters.ScoringProfile = queryBuilder.ScoreProfile;
            }

            if (queryBuilder.Refinements.Count > 0)
            {
                StringBuilder filter    = new StringBuilder();
                string        separator = string.Empty;

                foreach (var entry in queryBuilder.Refinements)
                {
                    foreach (string value in entry.Value)
                    {
                        filter.Append(separator);
                        filter.Append($"{entry.Key} eq '{EscapeFilterString(value)}'");
                        separator = " and ";
                    }
                }
                parameters.Filter = filter.ToString();
            }

            return(parameters);
        }
示例#2
0
        public async Task <GenericSearchResult> SearchAsync(SearchQueryBuilder queryBuilder)
        {
            if (queryBuilder.ScoreProfile == null && defaultScoreProfile != "")
            {
                queryBuilder.ScoreProfile = defaultScoreProfile;
            }
            var documentSearchResult = await this.searchClient.Documents.SearchAsync(queryBuilder.SearchText, BuildParameters(queryBuilder));

            return(this.mapper.Map(documentSearchResult));
        }