public void TestSearch()
        {
            SearchResultsRequest searchResultsRequest = new SearchResultsRequest();
            searchResultsRequest.Query = "halo";
            searchResultsRequest.IncludeAttributes = true;
            searchResultsRequest.Offset = 10;
            searchResultsRequest.Limit = 10;
            searchResultsRequest.DataOutputs = new EnumTypes.DataOutputType[] {
                    EnumTypes.DataOutputType.PRODUCTS,
                    EnumTypes.DataOutputType.CATEGORIES,
                    EnumTypes.DataOutputType.REFINEMENTS
                };
            searchResultsRequest.Offers = new EnumTypes.OfferType[] {
                    EnumTypes.OfferType.ALL
                };

            SearchResults searchResults = client.Search(searchResultsRequest);
            Assert.IsTrue(searchResults.TotalResultSize > 0);
            Assert.IsNotNull(searchResults.Categories);
            Assert.IsTrue(searchResults.Categories.Count > 0);
            Assert.IsNotNull(searchResults.Products);
            Assert.IsTrue(searchResults.Products.Count > 0);
            Assert.IsNotNull(searchResults.RefinementGroups);
            Assert.IsTrue(searchResults.RefinementGroups.Count > 0);
        }
        public SearchResults Search(SearchResultsRequest searchResultsRequest)
        {
            HttpWebRequest request = CatalogRequestBuilder.ConstructSearchRequest(apiKey, searchResultsRequest);
            SearchResults searchResults = ProcessBodylessRequest(request).ToObject<SearchResults>();

            return searchResults;
        }
        public static HttpWebRequest ConstructSearchRequest(string apiKey, SearchResultsRequest searchResultsRequest)
        {
            NameValueCollection queryParams = new NameValueCollection();
            queryParams.Add("apikey", apiKey);

            if (searchResultsRequest.Query != null)
            {
                queryParams.Add("q", searchResultsRequest.Query);
            }
            if (searchResultsRequest.ProductIds != null)
            {
                queryParams.Add("pids", searchResultsRequest.ProductIds);
            }
            if (searchResultsRequest.CategoryId != null || searchResultsRequest.RefinementIds != null)
            {
                string ids = FormatterUtils.CombineCategoryAndRefinementIds(searchResultsRequest.CategoryId, searchResultsRequest.RefinementIds);
                queryParams.Add("ids", ids);
            }
            if (searchResultsRequest.ListId != null)
            {
                queryParams.Add("listid", searchResultsRequest.ListId);
            }
            if (searchResultsRequest.Field != null)
            {
                queryParams.Add("searchfield", EnumUtils.StringValueOf(searchResultsRequest.Field));
            }
            if (searchResultsRequest.IncludeAttributes != null)
            {
                queryParams.Add("includeattributes", searchResultsRequest.IncludeAttributes.ToString().ToLower());
            }
            if (searchResultsRequest.DataOutputs != null)
            {
                queryParams.Add("dataoutput", FormatterUtils.FormatDataOutput(searchResultsRequest.DataOutputs));
            }
            if (searchResultsRequest.Offers != null)
            {
                queryParams.Add("offer", FormatterUtils.FormatOffer(searchResultsRequest.Offers));
            }
            if (searchResultsRequest.Sort != null)
            {
                queryParams.Add("sort", EnumUtils.StringValueOf(searchResultsRequest.Sort));
            }
            if (searchResultsRequest.Offset != null)
            {
                queryParams.Add("offset", searchResultsRequest.Offset.ToString().ToLower());
            }
            if (searchResultsRequest.Limit != null)
            {
                queryParams.Add("limit", searchResultsRequest.Limit.ToString().ToLower());
            }

            string queryString = HttpUtils.ToQueryString(queryParams);

            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Constants.URL_PREFIX + "/catalog/v4/search/" + queryString);
            request.Method = "GET";
            request.Accept = "application/json";

            return request;
        }