public static SuggestionQuery Select(this SuggestionQuery query, string selectField)
 {
     if (String.IsNullOrEmpty(query.Select))
     {
         query.Select = selectField;
     }
     else
     {
         query.Select += "," + selectField;
     }
     return(query);
 }
 public static SuggestionQuery OrderBy(this SuggestionQuery query, string orderByField)
 {
     if (String.IsNullOrEmpty(query.OrderBy))
     {
         query.OrderBy = orderByField;
     }
     else
     {
         query.OrderBy += "," + orderByField;
     }
     return(query);
 }
 public static SuggestionQuery SearchField(this SuggestionQuery query, string searchField)
 {
     if (String.IsNullOrEmpty(query.SearchFields))
     {
         query.SearchFields = searchField;
     }
     else
     {
         query.SearchFields += "," + searchField;
     }
     return(query);
 }
        /// <summary>
        /// Get suggestions from an index.
        /// </summary>
        /// <param name="indexName"></param>
        /// <param name="query"></param>
        /// <param name="cancellationToken">cancel token</param>
        /// <returns></returns>
        public Task<IApiResponse<SuggestionResult>> SuggestAsync(string indexName, SuggestionQuery query, CancellationToken cancellationToken)
        {
            var request = new ApiRequest("indexes/{0}/docs/suggest", HttpMethod.Get);
            if (!String.IsNullOrEmpty(query.Search))
                request.AddQueryParameter("search", query.Search);

            request.AddQueryParameter("fuzzy", query.Fuzzy ? Boolean.TrueString : Boolean.FalseString);

            if (!String.IsNullOrEmpty(query.SearchFields))
                request.AddQueryParameter("searchFields", query.SearchFields);

            if (query.Top > 0)
                request.AddQueryParameter("$top", query.Top.ToString(CultureInfo.InvariantCulture));

            if (!String.IsNullOrEmpty(query.OrderBy))
                request.AddQueryParameter("$orderby", query.OrderBy);
            if (!String.IsNullOrEmpty(query.Select))
                request.AddQueryParameter("$select", query.Select);

            if (!String.IsNullOrEmpty(query.SuggesterName))
                request.AddQueryParameter("suggesterName", query.SuggesterName);

            if (!String.IsNullOrEmpty(query.Filter))
                request.AddQueryParameter("$filter", query.Filter);

            return _connection.Execute<SuggestionResult>(request.WithUriParameter(indexName), cancellationToken);
        }
 /// <summary>
 /// Get suggestions from an index.
 /// </summary>
 /// <param name="indexName"></param>
 /// <param name="query"></param>
 /// <returns></returns>
 public Task<IApiResponse<SuggestionResult>> SuggestAsync(string indexName, SuggestionQuery query)
 {
     return SuggestAsync(indexName, query, default(CancellationToken));
 }
 public static SuggestionQuery Fuzzy(this SuggestionQuery query, bool fuzzy)
 {
     query.Fuzzy = fuzzy;
     return(query);
 }
 public static SuggestionQuery Filter(this SuggestionQuery query, string filter)
 {
     query.Filter = filter;
     return(query);
 }
 public static SuggestionQuery Top(this SuggestionQuery query, long top)
 {
     query.Top = top;
     return(query);
 }
 public static SuggestionQuery SuggesterName(this SuggestionQuery query, string suggesterName)
 {
     query.SuggesterName = suggesterName;
     return(query);
 }