Skip to content

Instantly share code, notes, and snippets.

@kdhollow
Created February 25, 2016 19:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kdhollow/bc3a90e33f14ac02d952 to your computer and use it in GitHub Desktop.
Save kdhollow/bc3a90e33f14ac02d952 to your computer and use it in GitHub Desktop.
AirportController
using System.Configuration;
using System.Linq;
using System.Threading.Tasks;
using System.Web.Mvc;
using AFDSearch.Models;
using BlackBarLabs.Search.Azure;
namespace AFDSearch.Controllers
{
public class AirportController : Controller
{
private readonly AzureSearchEngine azureSearchEngine;
private string indexName;
private string suggesterName;
public AirportController()
{
indexName = ConfigurationManager.AppSettings["SearchServiceIndexName"];
suggesterName = ConfigurationManager.AppSettings["SearchServiceSuggesterName"];
var engines = new SearchEngines("SearchServiceName", "SearchServiceApiKey");
azureSearchEngine = engines.AzureSearchEngine;
}
// GET: Search
public async Task<ActionResult> Search(AirportSearch model)
{
var result = await azureSearchEngine.SearchDocumentsAsync<Airport>(indexName, model.SearchText, null, true, null, null,
null,
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},
(s, longs) => { }, l => { });
var resultsModel = new AirportSearch();
resultsModel.SearchText = model.SearchText;
resultsModel.AirportSearchResults = result.ToList();
return View(resultsModel);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment