Announcement

Collapse
No announcement yet.

Add Alternative Search Engine (e.g. Google, etc.) Search Results link on vB5 Search Results page

Collapse
X
Collapse
First Prev Next Last
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Free Mod Add Alternative Search Engine (e.g. Google, etc.) Search Results link on vB5 Search Results page

    In some cases, the vB5 search results may not provide you what you're searching for in a forum. You could replace the default vB5 Search box with the Google Search box or add a Google search result link (and other search engines) together with the vB5 search results. These search engine links will redirect the user to their search results for your site.

    If you are more interested in the latter, then continue reading.

    Click image for larger version  Name:	search-results.png Views:	0 Size:	65.0 KB ID:	24098

    Before giving you the code to accomplish what is shown in the above screenshot, let me give you first the limitations/disadvantages of doing this modification:
    1. Your site must be public as search engines cannot index private pages.
    2. Your site will lose branding to search engines as users are taken out of your site and redirected to search engine search results page.
    3. Recent content from your forum may not be instantly available until search engines index your site.
    4. This mod requires editing the Search Results template which means the changes may cause template conflicts during upgrades.
    5. Since this requires template editing, this is not for vBCloud although there is another solution to implement it that will work on vBCloud.
    If you are okay with the above, then proceed with these steps:

    vB5 (Self-Hosted):
    1. Logon to AdminCP.
    2. Go to Styles → Search in Templates
    3. Choose the target style/theme in the "Search in Style" dropdown.
    4. In the "Search for Text" field, type widget_search_results.
    5. Select "Yes" in the "Search Titles Only" radio button.
    6. Click Find button.
    7. In the search results, double-click the template to edit it or select it then click Customize button.
    8. Find the following code (Click the Template input box and press Ctrl+F or Command+F)
      Code:
      <vb:if condition="!empty($nodes['ignored_keywords'])">
    9. Find its closing </vb:if> tag
    10. Below that code, insert the following code:
      Code:
      <vb:if condition="!empty($searchJSONParam['keywords'])">
      	<p class="alternative-search-engine-search h-margin-top-l">
      	Can't find what you're looking for? See <a href="https://www.google.com/search?q={vb:urlencode {vb:raw searchJSONParam.keywords}}+site%3A{vb:urlencode {vb:raw baseurl}}" target="_blank"><strong>Google</strong></a> search results for '{vb:raw searchJSONStructure.keywords}'.
      	</p>
      	</vb:if>
      That adds a Google search results link using the "site:" filter on search engines that search within the specified site URL which is your forum URL in this case. To add other search engine links, include the following hyperlink HTML:

      DuckDuckGo:
      HTML Code:
      <a href="https://duckduckgo.com/?q={vb:urlencode {vb:raw searchJSONParam.keywords}}+site%3A{vb:urlencode {vb:raw baseurl}}" target="_blank"><strong>DuckDuckGo</strong></a>
      Bing:
      HTML Code:
      <a href="https://www.bing.com/search?q={vb:urlencode {vb:raw searchJSONParam.keywords}}%20site%3A{vb:urlencode {vb:raw baseurl}}" target="_blank"><strong>Bing</strong></a>
      Yahoo:
      HTML Code:
      <a href="https://search.yahoo.com/search?p={vb:urlencode {vb:raw searchJSONParam.keywords}}+site%3A{vb:urlencode {vb:raw baseurl}}" target="_blank"><strong>Yahoo</strong></a>
      Yandex:
      HTML Code:
      <a href="https://yandex.com/search/?text={vb:urlencode {vb:raw searchJSONParam.keywords}}+site%3A{vb:urlencode {vb:raw baseurl}}" target="_blank"><strong>Yandex</strong></a>
      For example, on this site, I added Google and DuckDuckGo. Here's the code I used:
      Code:
      <vb:if condition="!empty($searchJSONStructure['keywords'])">
      	<p class="alternative-search-engine-search h-margin-top-l">
      	Can't find what you're looking for? See <a href="https://www.google.com/search?q={vb:urlencode {vb:raw searchJSONStructure.keywords}}+site%3A{vb:urlencode {vb:raw baseurl}}" target="_blank"><strong>Google</strong></a> or <a href="https://duckduckgo.com/?q={vb:urlencode {vb:raw searchJSONStructure.keywords}}+site%3A{vb:urlencode {vb:raw baseurl}}" target="_blank"><strong>DuckDuckGo</strong></a> search results for '{vb:raw searchJSONStructure.keywords}'.
      	</p>
      	</vb:if>
    11. Find the following code:
    12. Code:
      <vb:if condition="isset($nodes['errors'])">
    13. Below that code, insert the same code used in Step 10.
    14. Click Save button.
    15. Repeat Steps 2-14 for other active styles/themes on your forum (if any).

    vBCloud:

    vBCloud supports Template Hooks but unfortunately, there is no suitable template hook locations on the Search Result page. Thus, we'll just do the old-fashioned workaround for vBCloud by creating a hidden Static HTML module.
    1. Perform a search on your site. Any keyword is fine. We just want to go to the Search Result page.
    2. Enable Sitebuilder by toggling Edit Site slider to ON.
    3. Click Edit Page.
    4. Drag and drop a Static HTML module onto the page below the Search Results module.
    5. Edit the Static HTML Module by clicking the Pencil icon.
    6. Enter the following configuration:

      Title: Search Engine Links Script
      Show module at these screen sizes: (Uncheck ALL checkboxes)
      Module HTML:
      - Copy the code below.
      - Paste the code in a text editor.
      - Modify the searchEngines list in the code to remove search engines you don't want to display.
      - Copy the updated code and paste it into the Module HTML textbox.
      Code:
      <script>
      	(function() {
      
      	   // Remove other search engines as desired and
      	   // make sure there's no trailing comma at the last search engine in the list
      	   var searchEngines = ['Google', 'DuckDuckGo', 'Bing', 'Yahoo', 'Yandex'];
      
      	   // DO NOT MODIFY ANYTHING BELOW UNLESS YOU KNOW WHAT YOU'RE DOING!!!
      	   var searchInsertLocation = document.querySelector('.search-result-header .search-controls, .search-results-widget .widget-content .error');
      	   if (!searchInsertLocation) {
      	      return;
      	   }
      	   var keywords;
      	   var keywordsInput = document.querySelector('.js-search-keywords');
      	   if (!keywordsInput || !keywordsInput.value) {
      	      var qs = vBulletin.parseQueryString(location.href);
      	      if (qs.searchJSON) {
      	         try {
      	            var json = JSON.parse(qs.searchJSON);
      	            keywords = json.keywords;
      	         } catch (e) {
      	            return;
      	         }
      	      } else {
      	         return;
      	      }
      	   } else {
      	      keywords = keywordsInput.value;
      	   }
      
      	   var encodedKeywords = encodeURIComponent(keywords);
      	   var siteFilter = encodeURIComponent(' site:' + pageData.baseurl);
      	   var p = document.createElement('p');
      	   p.className = 'alternative-search-engine-search h-margin-top-l';
      	   var linkList = searchEngines.map(function(s) {
      	   var url = '';
      	   switch (s) {
      	      case 'Google':
      	         url = 'https://www.google.com/search?q=' + encodedKeywords + siteFilter;
      	         break;
      	      case 'DuckDuckGo':
      	         url = 'https://duckduckgo.com/?q=' + encodedKeywords + siteFilter;
      	         break;
      	      case 'Bing':
      	         url = 'https://www.bing.com/search?q=' + encodedKeywords + siteFilter;
      	         break;
      	      case 'Yahoo':
      	         url = 'https://search.yahoo.com/search?p=' + encodedKeywords + siteFilter;
      	         break;
      	      case 'Yandex':
      	         url = 'https://yandex.com/search/?text=' + encodedKeywords + siteFilter;
      	            break;
      	         default:
      	            break;
      	      }
      	      return url ? '<a href="' + url + '" target="_blank"><strong>' + s + '</strong></a>' : '';
      	   });
      	   var links = linkList.join(', ');
      	   var lastCommaIndex = links.lastIndexOf(',');
      	   if (lastCommaIndex !== -1) {
      	       links = links.substring(0, lastCommaIndex) + ' or ' + links.substring(lastCommaIndex + 2);
      	   }
      	   p.innerHTML = "Can't find what you're looking for? See " + links + " search results for \"" + keywords + "\".";
      	   searchInsertLocation.parentElement.insertBefore(p, searchInsertLocation);
      	})();
      	</script>
      Hide Title: Yes

      7. Click Save button.
      8. Click Save Page button.
      9. Click OK button.
      10. Click Save Page button.

    Demo:
    Try searching on this site or clicking this search result:

    https://vbmods.rocks/search?q=IP&sea...%3A%22IP%22%7D

    Enjoy!
    Last edited by glennrocksvb; 03-13-2022, 08:02 PM. Reason: Updated code
    Helpful? Donate. Thanks!
    Buy me a coffeePayPal QR Code
    Fast VPS Host for vBulletin:
    A2 Hosting & IONOS

    #2
    Nice mod, but in my case sending members to a generic search may bring up info on competitive forums. Is there a way to only show results from one forum URL?

    Comment


      #3
      It only searches within your forum as it adds "site: <your forum url>" filter to the search keyword.
      Last edited by glennrocksvb; 03-01-2022, 08:16 AM.
      Helpful? Donate. Thanks!
      Buy me a coffeePayPal QR Code
      Fast VPS Host for vBulletin:
      A2 Hosting & IONOS

      Comment


        #4
        Try clicking the sample search link I posted in the first post and observe the results from Google/DuckDuckGo and notice that all the results are coming from vbmods.rocks. Observe also the keyword input on Google/DuckDuckGo contains the "site:" filter pointing to vbmods.rocks.
        Helpful? Donate. Thanks!
        Buy me a coffeePayPal QR Code
        Fast VPS Host for vBulletin:
        A2 Hosting & IONOS

        Comment


        • Mitch
          Mitch commented
          Editing a comment
          After further review, Cloud can't change templates?

        #5
        Originally posted by Mitch View Post
        After further review, Cloud can't change templates?
        Right. That's why I mentioned this:

        Originally posted by glennrocksvb View Post
        Since this requires template editing, this is not for vBCloud although there is another solution to implement it that will work on vBCloud.
        I will create a separate mod that will work for vBCloud.
        Helpful? Donate. Thanks!
        Buy me a coffeePayPal QR Code
        Fast VPS Host for vBulletin:
        A2 Hosting & IONOS

        Comment


        • Mitch
          Mitch commented
          Editing a comment
          Thanks, Looking forward to it

        #6
        First post updated to add the code for vBCloud.
        Helpful? Donate. Thanks!
        Buy me a coffeePayPal QR Code
        Fast VPS Host for vBulletin:
        A2 Hosting & IONOS

        Comment


          #7
          I noticed that short keywords such as "a", "the", "ip" and the like that are dropped by vB, are not passed to search engines. Some of these short keywords may produce results in the search engines. I have updated the code in the first post to pass whatever user entered as keywords to search engines without dropping short keywords.

          Also when vB does not find any results showing "Your criteria is not restrictive enough" or "There are no results that meet this criteria" error , it would be good to also show the alternative search engine search result link as that may produce some results. I have also updated the code in the first post to do that.
          Helpful? Donate. Thanks!
          Buy me a coffeePayPal QR Code
          Fast VPS Host for vBulletin:
          A2 Hosting & IONOS

          Comment

          Users Viewing This Page

          Collapse

          There is 1 user viewing this forum topic.

          • Guest Guest

          Latest Posts

          Collapse

          Working...
          X
          Searching...Please wait.
          An unexpected error was returned: 'Your submission could not be processed because you have logged in since the previous page was loaded.

          Please push the back button and reload the previous window.'
          An unexpected error was returned: 'Your submission could not be processed because the token has expired.

          Please push the back button and reload the previous window.'
          An internal error has occurred and the module cannot be displayed.
          There are no results that meet this criteria.
          Search Result for "|||"