Search code examples
javascriptgoogle-custom-search

Google Custom Site Search - Promotion Not Displaying


I'm using the standard custom search installation. I have promotions setup to my account.

I have the following:

    google.load('search', '1', { language: 'en', style: google.loader.themes.MINIMALIST });
    google.setOnLoadCallback(function () {
        var customSearchOptions = {};
        customSearchOptions[google.search.Search.RESTRICT_EXTENDED_ARGS] = { 'as_sitesearch': '' };
        var customSearchControl = new google.search.CustomSearchControl('CSE-UNIQUE-ID', customSearchOptions);
        customSearchControl.setResultSetSize(google.search.Search.FILTERED_CSE_RESULTSET);
        var options = new google.search.DrawOptions();
        options.setAutoComplete(true);
        customSearchControl.setLinkTarget(google.search.Search.LINK_TARGET_SELF);
        customSearchControl.draw('cse', options);
        customSearchControl.execute(getParameterByName("q"));
    }, true);


    function getParameterByName(name) {
        name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
        var regexS = "[\\?&]" + name + "=([^&#]*)";
        var regex = new RegExp(regexS);
        var results = regex.exec(window.location.search);

        if (results == null) {
            return "";
        }

        else {
            return decodeURIComponent(results[1].replace(/\+/g, " "));
        }
    }

I am setting the javascript object field: as_sitesearch via a CMS, so the code can be used across sites. When the field is populated with i.e ".example.com" the promotions do not display in the search results. They do on the other hand display in the auto-complete.

When the as_sitesearch field is empty the promotions display? Why is this?

Thanks


Solution

  • It appears that when a link for a promotion is linking to a sub-domain or another domain totally, the search filter removes the promotion from the results as its not within the given domain in the as_sitesearch field.

    Although it appears the autocomplete search does not use the filter given and therefore displays the promotions.