Article

How to access the Page directly from the SearchBox Autocomplete?

« Go Back

Information

 
EnvironmentProduct: Sitefinity
Versions: 5.x, 6.x, 7.x, 8.x, 9.x
OS: All supported OS versions
Database: All supported Microsoft SQL Server versions
Question/Problem Description
How to access the Page directly from the SearchBox Autocomplete without having to wait for the Search results ?
Steps to Reproduce
Clarifying Information
Error Message
Defect/Enhancement Number
Cause
Resolution
By design it is not currently possible to achieve this behavior. Note that the service that is called via Ajax returns a json of strings with the suggestions, not Urls:
 
namespace Telerik.Sitefinity.Search.Impl.Services.DTO
{
/// Class that represents the service stack suggestions response object.
public class SuggestionsResponse
{
/// <summary>
/// Gets or sets the suggestions result
public string[] Suggestions { get; set; }
}
}

Class Telerik.Sitefinity.Search.Impl.Services.SearchWebService
 
/// Gets search suggestions
/// <param name="request">The request</param>
/// <returns>The suggestions response</returns>
[AddHeader(ContentType = "application/json")]
public SuggestionsResponse Get(SuggestionsRequest request)
{
using (new CultureRegion(request.Language))
{
var text = request.Text;
var resultSuggestions = new HashSet<string>();
if (!string.IsNullOrEmpty(text))
{
IEnumerable<string> suggestionFieldsArray = string.IsNullOrEmpty(request.SuggestionFields) ? new string[0] : request.SuggestionFields.Split(',').Select(s => s.Trim());
var queryBuilder = ObjectFactory.Resolve<IQueryBuilder>();
var searchQuery = queryBuilder.BuildQuery(text, suggestionFieldsArray);
searchQuery.IndexName = request.IndexName;
searchQuery.Skip = 0;
searchQuery.Take = 10;
searchQuery.EnableExactMatch = false;
searchQuery.HighlightedFields = suggestionFieldsArray;
var result = ServiceBus.ResolveService<ISearchService>().Search(searchQuery);
var suggestionsResult = result.Select(d => d.GetValue(PublishingConstants.SuggestionsField) as List<string>);
var enoughResultsFound = false;
var maxSuggestionsCount = Config.Get<SearchConfig>().MaxSuggestionsCount;
foreach (var suggestions in suggestionsResult)
{
foreach (var suggestion in suggestions)
{
var currentSuggestion = this.FormatSuggestion(suggestion, text);
if (!string.IsNullOrEmpty(currentSuggestion))
resultSuggestions.Add(currentSuggestion);
if (resultSuggestions.Count >= maxSuggestionsCount)
{
enoughResultsFound = true;
break;
}
}
if (enoughResultsFound) break;
}
}
return new SuggestionsResponse() { Suggestions = resultSuggestions.ToArray() };
}
}







 
Workaround
As a workaround consider implementing a custom service as well as customizing the SearchBox control.

A related article is listed below:

How to show the content's title in the Search Suggestions (Autocomplete) instead


 
Notes
Attachment 
Last Modified Date3/20/2017 3:32 PM
Disclaimer

The origins of the information on this site may be internal or external to Progress Software Corporation (“Progress”). Progress Software Corporation makes all reasonable efforts to verify this information. However, the information provided is for your information only. Progress Software Corporation makes no explicit or implied claims to the validity of this information.

Any sample code provided on this site is not supported under any Progress support program or service. The sample code is provided on an "AS IS" basis. Progress makes no warranties, express or implied, and disclaims all implied warranties including, without limitation, the implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample code is borne by the user. In no event shall Progress, its employees, or anyone else involved in the creation, production, or delivery of the code be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample code, even if Progress has been advised of the possibility of such damages.



Feedback
 
Was this article helpful?

   

Your feedback is appreciated.

Please tell us how we can make this article more useful.



Characters Remaining: 255