// GET: Search
        public async Task <ActionResult> Search(AirportSearch model)
        {
            // By default, we want to get back no results, but we want to get facet and count information for the entire result set
            int?top        = model.Top == 0 ? DefaultTopCount : model.Top;
            var searchText = model.SearchText;

            if (string.IsNullOrEmpty(searchText) && string.IsNullOrEmpty(model.Filter))
            {
                searchText = "*";
                top        = 0;
            }

            // Set up facets
            var facetfields = new List <string>()
            {
                "Region", "State", "Chart"
            };
            var facetResults = new List <FacetInfo>();

            long count  = 0;
            var  result = await azureSearchEngine.SearchDocumentsAsync <Airport>(indexName, searchText, facetfields, true, top, model.Skip,
                                                                                 model.Filter,
                                                                                 airport => new Airport()
            {
                Id = airport.Id, Identifier = airport.Identifier, Name = airport.Name, City = airport.City, State = airport.State, Chart = airport.Chart, Region = airport.Region, AfdLink = airport.AfdLink
            },
                                                                                 (facetName, facets) =>
            {
                facetResults.Add(new FacetInfo()
                {
                    FacetName = facetName, Facets = facets
                });
            },
                                                                                 documentCount => { if (null != documentCount)
                                                                                                    {
                                                                                                        count = documentCount.Value;
                                                                                                    }
                                                                                 });

            var resultsModel = new AirportSearch();

            resultsModel.SearchText           = model.SearchText;
            resultsModel.AirportSearchResults = result.ToList();
            resultsModel.FacetResults         = facetResults;
            resultsModel.Filter = model.Filter;
            resultsModel.Top    = model.Top;
            resultsModel.Skip   = model.Skip;
            resultsModel.Count  = count;


            return(View(resultsModel));
        }
        public async Task Search()
        {
            var exception     = default(Exception);
            var distributorId = Guid.NewGuid().ToString();

            try
            {
                await CreateIndexInternalAsync(distributorId);

                var products = CreateProductList();
                await azureSearchEngine.IndexItemsAsync <Product>(distributorId, products, async indexName =>
                {
                    await CreateIndexInternalAsync(indexName);
                });

                await Task.Delay(5000);  // Azure Search says the indexing on their side could take some time.  Particularly on a shared search instance.

                var foundDocs = await azureSearchEngine.SearchDocumentsAsync <Product>(distributorId, "Yellow", null, false, 50, 0, null,
                                                                                       product => product, (s, longs) => { }, l => { var count = l; });

                var found = false;
                foreach (var doc in foundDocs)
                {
                    if (doc.ProductName.Contains("Yellow"))
                    {
                        found = true;
                    }
                }
                Assert.IsTrue(found);
            }
            catch (Exception ex)
            {
                exception = ex;
            }
            finally
            {
                await DeleteIndexInternalAsync(distributorId);

                if (default(Exception) != exception)
                {
                    throw exception;
                }
            }
        }