Skip to main content
Added a permanent link under the current one.
Source Link

From my testing, it does it by default. So I followed this page: https://developers.coveo.com/xdisplay/CIIUAgSitecoreV4/Provide+Result+Suggestions and I added the "Coveo Search Resources", "Coveo Search Box" and "Coveo Omnibox Result List" to my header. I now have suggestions on everything within my index.

I made a mistake in my original answer, I was using field-based query suggestions : https://developers.coveo.com/xdisplay/BoIUAgSitecoreV4/Provide+Query+Suggestions

To have the same query completion behavior with the OmniboxResultList (Results Suggestions) is not possible without adding a wildcard, since it does a full query against the index, while query suggestions does a field listing call:    https://developers.coveo.com/xdisplay/lQEvSearchREST/Listing+Values+of+a+Field

For more information on the PopulateOmnibox function: https://developers.coveo.com/xdisplay/U4GfAQJsSearchV1/Providing+Suggestions+for+the+Omnibox

From my testing, it does it by default. So I followed this page: https://developers.coveo.com/x/CIIUAg and I added the "Coveo Search Resources", "Coveo Search Box" and "Coveo Omnibox Result List" to my header. I now have suggestions on everything within my index.

I made a mistake in my original answer, I was using field-based query suggestions : https://developers.coveo.com/x/BoIUAg

To have the same query completion behavior with the OmniboxResultList (Results Suggestions) is not possible without adding a wildcard, since it does a full query against the index, while query suggestions does a field listing call:  https://developers.coveo.com/x/lQEv

For more information on the PopulateOmnibox function: https://developers.coveo.com/x/U4GfAQ

From my testing, it does it by default. So I followed this page: developers.coveo.com/display/SitecoreV4/Provide+Result+Suggestions and I added the "Coveo Search Resources", "Coveo Search Box" and "Coveo Omnibox Result List" to my header. I now have suggestions on everything within my index.

I made a mistake in my original answer, I was using field-based query suggestions : https://developers.coveo.com/display/SitecoreV4/Provide+Query+Suggestions

To have the same query completion behavior with the OmniboxResultList (Results Suggestions) is not possible without adding a wildcard, since it does a full query against the index, while query suggestions does a field listing call:  https://developers.coveo.com/display/SearchREST/Listing+Values+of+a+Field

For more information on the PopulateOmnibox function: https://developers.coveo.com/display/JsSearchV1/Providing+Suggestions+for+the+Omnibox

Changed
Source Link

From my testing, it does it by default. So I followed this page: https://developers.coveo.com/display/public/SitecoreV4/Provide+Result+Suggestionshttps://developers.coveo.com/x/CIIUAg and I added the "Coveo Search Resources", "Coveo Search Box" and "Coveo Omnibox Result List" to my header. I now have suggestions on everything within my index.

I made a mistake in my original answer, I was using field-based query suggestions : https://developers.coveo.com/display/SitecoreV4/Provide+Query+Suggestions#ProvideQuerySuggestions-FieldBasedSuggestionshttps://developers.coveo.com/x/BoIUAg

To have the same query completion behavior with the OmniboxResultList (Results Suggestions) is not possible without adding a wildcard, since it does a full query against the index, while query suggestions does a field listing call: https://developers.coveo.com/display/SearchREST/Listing+Values+of+a+Fieldhttps://developers.coveo.com/x/lQEv

For more information on the PopulateOmnibox function: https://developers.coveo.com/display/JsSearchV1/Providing+Suggestions+for+the+Omniboxhttps://developers.coveo.com/x/U4GfAQ

From my testing, it does it by default. So I followed this page: https://developers.coveo.com/display/public/SitecoreV4/Provide+Result+Suggestions and I added the "Coveo Search Resources", "Coveo Search Box" and "Coveo Omnibox Result List" to my header. I now have suggestions on everything within my index.

I made a mistake in my original answer, I was using field-based query suggestions : https://developers.coveo.com/display/SitecoreV4/Provide+Query+Suggestions#ProvideQuerySuggestions-FieldBasedSuggestions

To have the same query completion behavior with the OmniboxResultList (Results Suggestions) is not possible without adding a wildcard, since it does a full query against the index, while query suggestions does a field listing call: https://developers.coveo.com/display/SearchREST/Listing+Values+of+a+Field

For more information on the PopulateOmnibox function: https://developers.coveo.com/display/JsSearchV1/Providing+Suggestions+for+the+Omnibox

From my testing, it does it by default. So I followed this page: https://developers.coveo.com/x/CIIUAg and I added the "Coveo Search Resources", "Coveo Search Box" and "Coveo Omnibox Result List" to my header. I now have suggestions on everything within my index.

I made a mistake in my original answer, I was using field-based query suggestions : https://developers.coveo.com/x/BoIUAg

To have the same query completion behavior with the OmniboxResultList (Results Suggestions) is not possible without adding a wildcard, since it does a full query against the index, while query suggestions does a field listing call: https://developers.coveo.com/x/lQEv

For more information on the PopulateOmnibox function: https://developers.coveo.com/x/U4GfAQ

Typo in querty
Source Link
    Coveo.$(function () {
        var searchbox = Coveo.$('#@Model.SearchboxId');
            if (typeof(CoveoForSitecore) !== 'undefined') {
                CoveoForSitecore.componentsOptions = @(Html.Raw(Model.GetJavaScriptInitializationOptions()));
    
                //Here is the part where I access the suggestions of my search box
                CoveoForSitecore.componentsOptions.FieldsSuggestions = { 
                    omniboxSuggestionOptions: {
                    //This queryOverride is optional, you can use it to filter the suggestions
                        queryOverride: '@Model.ToCoveoFieldName(haslayout"haslayout")=="1"',
                        //The onSelect function is the one we want to override in order to open the suggestion 
                        onSelect: function (valueSelected, populateOmniBoxEventArgs) {
                            populateOmniBoxEventArgs.closeOmnibox();
                            //This is the core of the code, you will launch a new query to find the value selected in the suggestion and open it directly
                            Coveo.SearchEndpoint.endpoints["default"]
                                .search({
                                    q: '@systitle=="''@Model.ToCoveoFieldName("title")' + '=="' + valueSelected + '"'
                                })
                                .done(function (results) {
                                    var foundResult = Coveo._.find(results.results, function(result){
                                            return valueSelected == result.raw.systitle;
                                        });
                                    if(foundResult) {
                                    // This logCustomEvent is optional but should be used in order to track in the Usage Analytics
                                        logCustomEvent('enter the name of the event');                                  
                                        window.location = foundResult.clickUri;
                                    } else {
                                        logger.warn("Selected suggested result," + valueSelected + " , not found.");
                                    }
                                })
                        }
                    }   
                }          
          
                searchbox.coveoForSitecore('initSearchbox', CoveoForSitecore.componentsOptions);
                             
            } else {
                searchbox.coveo('initSearchbox',
                                '@Model.GetSearchPageUrl()');
            }
            searchbox.find(".CoveoSearchbox input").attr("placeholder", '@Model.SearchboxPlaceholderText');
    Coveo.$(function () {
        var searchbox = Coveo.$('#@Model.SearchboxId');
            if (typeof(CoveoForSitecore) !== 'undefined') {
                CoveoForSitecore.componentsOptions = @(Html.Raw(Model.GetJavaScriptInitializationOptions()));
    
                //Here is the part where I access the suggestions of my search box
                CoveoForSitecore.componentsOptions.FieldsSuggestions = { 
                    omniboxSuggestionOptions: {
                    //This queryOverride is optional, you can use it to filter the suggestions
                        queryOverride: '@Model.ToCoveoFieldName(haslayout)=="1"',
                        //The onSelect function is the one we want to override in order to open the suggestion 
                        onSelect: function (valueSelected, populateOmniBoxEventArgs) {
                            populateOmniBoxEventArgs.closeOmnibox();
                            //This is the core of the code, you will launch a new query to find the value selected in the suggestion and open it directly
                            Coveo.SearchEndpoint.endpoints["default"]
                                .search({
                                    q: '@systitle=="' + valueSelected + '"'
                                })
                                .done(function (results) {
                                    var foundResult = Coveo._.find(results.results, function(result){
                                            return valueSelected == result.raw.systitle;
                                        });
                                    if(foundResult) {
                                    // This logCustomEvent is optional but should be used in order to track in the Usage Analytics
                                        logCustomEvent('enter the name of the event');                                  
                                        window.location = foundResult.clickUri;
                                    } else {
                                        logger.warn("Selected suggested result," + valueSelected + " , not found.");
                                    }
                                })
                        }
                    }   
                }          
          
                searchbox.coveoForSitecore('initSearchbox', CoveoForSitecore.componentsOptions);
                             
            } else {
                searchbox.coveo('initSearchbox',
                                '@Model.GetSearchPageUrl()');
            }
            searchbox.find(".CoveoSearchbox input").attr("placeholder", '@Model.SearchboxPlaceholderText');
    Coveo.$(function () {
        var searchbox = Coveo.$('#@Model.SearchboxId');
            if (typeof(CoveoForSitecore) !== 'undefined') {
                CoveoForSitecore.componentsOptions = @(Html.Raw(Model.GetJavaScriptInitializationOptions()));
    
                //Here is the part where I access the suggestions of my search box
                CoveoForSitecore.componentsOptions.FieldsSuggestions = { 
                    omniboxSuggestionOptions: {
                    //This queryOverride is optional, you can use it to filter the suggestions
                        queryOverride: '@Model.ToCoveoFieldName("haslayout")=="1"',
                        //The onSelect function is the one we want to override in order to open the suggestion 
                        onSelect: function (valueSelected, populateOmniBoxEventArgs) {
                            populateOmniBoxEventArgs.closeOmnibox();
                            //This is the core of the code, you will launch a new query to find the value selected in the suggestion and open it directly
                            Coveo.SearchEndpoint.endpoints["default"]
                                .search({
                                    q: '@Model.ToCoveoFieldName("title")' + '=="' + valueSelected + '"'
                                })
                                .done(function (results) {
                                    var foundResult = Coveo._.find(results.results, function(result){
                                            return valueSelected == result.raw.systitle;
                                        });
                                    if(foundResult) {
                                    // This logCustomEvent is optional but should be used in order to track in the Usage Analytics
                                        logCustomEvent('enter the name of the event');                                  
                                        window.location = foundResult.clickUri;
                                    } else {
                                        logger.warn("Selected suggested result," + valueSelected + " , not found.");
                                    }
                                })
                        }
                    }   
                }          
          
                searchbox.coveoForSitecore('initSearchbox', CoveoForSitecore.componentsOptions);
                             
            } else {
                searchbox.coveo('initSearchbox',
                                '@Model.GetSearchPageUrl()');
            }
            searchbox.find(".CoveoSearchbox input").attr("placeholder", '@Model.SearchboxPlaceholderText');
Added the old code
Source Link
Loading
Edit for Sitecore MVC
Source Link
Loading
Code Formatting
Source Link
Gatogordo
  • 20.3k
  • 2
  • 39
  • 100
Loading
Corrected my previous mistake
Source Link
Loading
Source Link
Loading