public DefaultServerAutocompleteProcessor(TagHelperContext context, TagHelperOutput output, AutocompleteTagHelper tag, AutocompleteOptions options) { this.context = context; this.output = output; this.tag = tag; this.options = options; }
public static async Task <IActionResult> Run( [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req, ILogger log) { log.LogInformation("C# HTTP trigger function processed a request."); string q = req.Query["q"]; string top = req.Query["top"]; string suggester = req.Query["suggester"]; string requestBody = await new StreamReader(req.Body).ReadToEndAsync(); dynamic data = JsonConvert.DeserializeObject(requestBody); q = q ?? data?.q; top = top ?? data?.top; suggester = suggester ?? data?.suggester; AutocompleteOptions options = new AutocompleteOptions() { Size = int.Parse(top) }; var response = await searchClient.AutocompleteAsync(q, suggester, options); var output = new Dictionary <string, List <AutocompleteItem> >(); output["suggestions"] = response.Value.Results.ToList(); return(new OkObjectResult(output)); }
public void OnDisconnectStops() { LaraUI.InternalContext.Value = Context; var x = new AutocompleteElement(); var provider = new MyProvider(); var options = new AutocompleteOptions { Provider = provider, AutoFocus = true, MinLength = 2, Strict = true }; var doc = new Document(new MyPage(), 100); var bridge = new Mock <IJsBridge>(); Context.JSBridge = bridge.Object; doc.Body.AppendChild(x); x.Start(options); Assert.Equal(1, AutocompleteService.RegisteredCount); Assert.Same(options, x.GetOptions()); x.Remove(); Assert.Equal(0, AutocompleteService.RegisteredCount); }
public void AutocompleteStarts() { LaraUI.InternalContext.Value = Context; var x = new AutocompleteElement(); var provider = new MyProvider(); var options = new AutocompleteOptions { Provider = provider, AutoFocus = true, MinLength = 2, Strict = true }; x.Start(options); var doc = new Document(new MyPage(), 100); var bridge = new Mock <IJsBridge>(); Context.JSBridge = bridge.Object; const string code = "LaraUI.autocompleteApply(context.Payload);"; var payload = new AutocompletePayload { AutoFocus = options.AutoFocus, ElementId = x.InnerInput.Id, MinLength = options.MinLength, Strict = options.Strict }; var json = LaraUI.JSON.Stringify(payload); bridge.Setup(x1 => x1.Submit(code, json)); doc.Body.AppendChild(x); bridge.Verify(x2 => x2.Submit(code, json), Times.Once); }
public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output) { if (DisplayProperty == null && (DisplayPropertyExplorer == null || DisplayPropertyExpressionOverride == null)) { new ArgumentNullException("display-property/display-expression-override+display-explorer"); } if (For == null && (ForPropertyExplorer == null || ForExpressionOverride == null)) { new ArgumentNullException("asp-for/for-expression-override+for-explorer"); } if (string.IsNullOrWhiteSpace(ItemsDisplayProperty)) { new ArgumentNullException("items-display-property"); } if (string.IsNullOrWhiteSpace(ItemsValueProperty)) { new ArgumentNullException("items-value-property"); } if (string.IsNullOrWhiteSpace(ItemsUrl)) { new ArgumentNullException("items-url"); } if (string.IsNullOrWhiteSpace(UrlToken)) { new ArgumentNullException("url-token"); } if (string.IsNullOrWhiteSpace(DataSetName)) { new ArgumentNullException("dataset-name"); } if (MaxResults == 0) { MaxResults = 20; } if (MinChars == 0) { MinChars = 3; } var currProvider = ViewContext.TagHelperProvider(); var resolver = jsonOptions.SerializerSettings.ContractResolver as DefaultContractResolver; var vd = ViewContext.ViewData; var options = new AutocompleteOptions { Generator = generator, PropertyResolver = resolver != null ? resolver.GetResolvedPropertyName : new Func <string, string>(x => x), ForcedValueName = currProvider.GenerateNames ? vd.GetFullHtmlFieldName(ForExpressionOverride ?? For.Name) : null, ForcedDisplayName = currProvider.GenerateNames ? vd.GetFullHtmlFieldName(DisplayPropertyExpressionOverride ?? DisplayProperty.Name) : null, NoId = !currProvider.GenerateNames || ViewContext.IsFilterRendering() }; await currProvider.GetTagProcessor(TagName)(context, output, this, options, null); }
public JsonResult AutoComplete(string searchText) { SearchClient searchClient = new SearchClient(new Uri(_configuration.GetValue <string>("AZURE_SEARCH_URI")), _configuration.GetValue <string>("AZURE_SEARCH_INDEX"), new AzureKeyCredential(_configuration.GetValue <string>("AZURE_SEARCH_KEY"))); AutocompleteOptions autocompleteOptions = new AutocompleteOptions() { Mode = AutocompleteMode.OneTermWithContext }; Response <AutocompleteResults> autocompleteResult = searchClient.Autocomplete(searchText, "documentSuggester", autocompleteOptions); // Convert the autocompleteResult results to a list that can be displayed in the client. List <string> searchResults = autocompleteResult.Value.Results.Select(x => x.Text).ToList(); return(Json(searchResults)); }
public async Task Given_Top_As_5_Autocomplete_Returns_The_Top_5() { var api = Helpers.ApiHelper.GetApi(); var options = new AutocompleteOptions { Top = 5 }; var result = await api.Autocomplete("PE15", options : options); result.IsSuccess.ShouldBeTrue(); result.Success.Suggestions.Length.ShouldBe(5); }
public async Task <Result <SuccessfulAutocomplete> > Autocomplete(string term, AutocompleteOptions options = default, AccessToken accessToken = default, CancellationToken cancellationToken = default) { options = options ?? new AutocompleteOptions(); var path = GetAutocompletePath(term); var requestUri = GetUri(path); return(await HttpPost <SuccessfulAutocomplete>(requestUri, data : options, administrationOrApiKey : AddressLookupKey, token : accessToken, cancellationToken : cancellationToken)); }
public async Task Given_All_Autocomplete_Returns_All_Suggestions_For_Postcode() { var api = Helpers.ApiHelper.GetApi(); var options = new AutocompleteOptions { All = true }; var result = await api.Autocomplete("PE15 0SR", options : options); result.IsSuccess.ShouldBeTrue(); result.Success.Suggestions.Length.ShouldBeGreaterThan(6); }
public async Task Given_Template_Autocomplete_Returns_Templated_Suggestions() { var api = Helpers.ApiHelper.GetApi(); var options = new AutocompleteOptions { Template = "{outcode}--test!" }; var result = await api.Autocomplete("PE15 0SR", options : options); result.IsSuccess.ShouldBeTrue(); result.Success.Suggestions[0].Address.StartsWith("PE15"); }
public async Task Given_No_Location_Autocomplete_Returns_Suggestions_From_London() { var api = Helpers.ApiHelper.GetApi(); var options = new AutocompleteOptions { }; var result = await api.Autocomplete("Homestead Road", options : options); result.IsSuccess.ShouldBeTrue(); result.Success.Suggestions.Length.ShouldBeGreaterThan(0); result.Success.Suggestions.First().Address.Contains("London").ShouldBeTrue(); }
public void AutocompleteOptionsStore() { var provider = new MyProvider(); var options = new AutocompleteOptions { Provider = provider, AutoFocus = true, MinLength = 2, Strict = true }; Assert.Same(provider, options.Provider); Assert.True(options.AutoFocus); Assert.Equal(2, options.MinLength); Assert.True(options.Strict); }
public async Task <List <string> > AutoCompleteAndSuggestAsync(string term) { if (string.IsNullOrEmpty(term)) { return(new List <string>()); } // Setup the type-ahead search parameters. var ap = new AutocompleteOptions() { Mode = AutocompleteMode.OneTermWithContext, Size = 1, }; var autocompleteResult = await _searchclient.AutocompleteAsync(term, "sg", ap); // Setup the suggest search parameters. var sp = new SuggestOptions() { Size = 8, }; // Only one suggester can be specified per index. The name of the suggester is set when the suggester is specified by other API calls. // The suggester for the hotel database is called "sg" and simply searches the hotel name. var suggestResult = await _searchclient.SuggestAsync <Hotel>(term, "sg", sp).ConfigureAwait(false); // Create an empty list. var results = new List <string>(); if (autocompleteResult.Value.Results.Count > 0) { // Add the top result for type-ahead. results.Add(autocompleteResult.Value.Results[0].Text); } else { // There were no type-ahead suggestions, so add an empty string. results.Add(""); } for (int n = 0; n < suggestResult.Value.Results.Count; n++) { // Now add the suggestions. results.Add(suggestResult.Value.Results[n].Text); } return(results); }
public async Task <ActionResult> AutoCompleteAsync(string term) { InitSearch(); // Setup the autocomplete parameters. var ap = new AutocompleteOptions() { Mode = AutocompleteMode.OneTermWithContext, Size = 6 }; var autocompleteResult = await _searchClient.AutocompleteAsync(term, "sg", ap).ConfigureAwait(false); // Convert the autocompleteResult results to a list that can be displayed in the client. List <string> autocomplete = autocompleteResult.Value.Results.Select(x => x.Text).ToList(); return(new JsonResult(autocomplete)); }
public async Task <ICollection <string> > SuggestAsync(string query) { if (string.IsNullOrWhiteSpace(query)) { return(new string[0]); } var options = new AutocompleteOptions() { Mode = AutocompleteMode.OneTermWithContext, Size = 10 }; // Convert the autocompleteResult results to a list that can be displayed in the client. var autocompleteResult = await this.concertsIndexClient.AutocompleteAsync(query, "default-suggester", options).ConfigureAwait(false); return(autocompleteResult.Value.Results.Select(x => x.Text).ToList()); }
public async Task Given_Yorkshire_Location_Autocomplete_Returns_Suggestions_From_Yorkshire() { var api = Helpers.ApiHelper.GetApi(); var options = new AutocompleteOptions { }; options.Location.Latitude = 53.42416763305664; options.Location.Longitude = -1.45220148563385; var result = await api.Autocomplete("Homestead Road", options : options); result.IsSuccess.ShouldBeTrue(); result.Success.Suggestions.Length.ShouldBeGreaterThan(0); result.Success.Suggestions.First().Address.Contains("Yorkshire").ShouldBeTrue(); }
public AutocompleteResults Autocomplete(string searchText, bool fuzzy) { // Execute search based on query string try { AutocompleteOptions options = new AutocompleteOptions() { Mode = AutocompleteMode.OneTermWithContext, UseFuzzyMatching = fuzzy, Size = 8 }; return _searchClient.Autocomplete(searchText, "sg", options); } catch (Exception ex) { Console.WriteLine("Error querying index: {0}\r\n", ex.Message.ToString()); } return null; }
public async Task Given_Northamptonshire_County_Filter_Autocomplete_Returns_Only_Suggestions_From_Northampton() { var api = Helpers.ApiHelper.GetApi(); var options = new AutocompleteOptions { }; options.Filter.County = "Northamptonshire"; var result = await api.Autocomplete("PE15 0SR", options : options); result.IsSuccess.ShouldBeTrue(); result.Success.Suggestions.Length.ShouldBe(0); var result2 = await api.Autocomplete("NN1 3ER", options : options); result2.IsSuccess.ShouldBeTrue(); result2.Success.Suggestions.Length.ShouldBeGreaterThan(0); }
/// <summary> /// Build a <see cref="AutocompleteOptions"/> object. /// </summary> /// <returns>the <see cref="AutocompleteOptions"/> object.</returns> public override AutocompleteOptions Build() { AutocompleteOptions autocompleteOptions = new AutocompleteOptions() { Mode = this.Mode, Filter = this.Filter, HighlightPostTag = this.HighlightPostTag, HighlightPreTag = this.HighlightPreTag, MinimumCoverage = this.MinimumCoverage, Size = this.Size, UseFuzzyMatching = this.UseFuzzyMatching, }; if (this.SearchFields != null) { foreach (string searchField in this.SearchFields) { autocompleteOptions.SearchFields.Add(searchField); } } return(autocompleteOptions); }
public async void AutocompleteServiceRun() { LaraUI.InternalContext.Value = Context; var x = new AutocompleteElement(); var provider = new MyProvider(); var options = new AutocompleteOptions { Provider = provider, AutoFocus = true, MinLength = 2, Strict = true, }; var doc = new Document(new MyPage(), 100); var bridge = new Mock <IJsBridge>(); Context.JSBridge = bridge.Object; doc.Body.AppendChild(x); x.Start(options); var service = new AutocompleteService(); var request = new AutocompleteRequest { Key = x.AutocompleteId, Term = "B" }; Context.RequestBody = LaraUI.JSON.Stringify(request); var text = await service.Execute(); var response = LaraUI.JSON.Parse <AutocompleteResponse>(text); Assert.Equal(3, response.Suggestions !.Count); var item = response.Suggestions[0]; Assert.Equal("Red", item.Label); Assert.Equal("R", item.Code); }
public jQueryObject Autocomplete(AutocompleteOptions options) { return(null); }
public jQueryObject Autocomplete(AutocompleteOptions options) { return null; }
public virtual Response <AutocompleteResult> AutocompleteGet(string searchText, string suggesterName, RequestOptions requestOptions = null, AutocompleteOptions autocompleteOptions = null, CancellationToken cancellationToken = default) { using var scope = _clientDiagnostics.CreateScope("DocumentsClient.AutocompleteGet"); scope.Start(); try { return(RestClient.AutocompleteGet(searchText, suggesterName, requestOptions, autocompleteOptions, cancellationToken)); } catch (Exception e) { scope.Failed(e); throw; } }