Created
February 25, 2016 19:42
-
-
Save kdhollow/bc3a90e33f14ac02d952 to your computer and use it in GitHub Desktop.
AirportController
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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