I just did a ChatGPT query on this topic and these are the results:
Using the Discourse search facility, can the search incorporate a Google search at the same time?
ChatGPT said:
Discourse’s built-in search doesn’t natively support combining its results with Google search, but you can modify it to achieve this in a few ways:
- Modify the Search Interface (UI Approach)
You can add a “Search with Google” button next to the built-in search bar. This can be done via Discourse’s theme components by adding a link that redirects to Google with site:yourforum.com pre-filled.
Steps:
Go to Admin → Customize → Themes in Discourse.
Edit the theme component and add a button in the search bar template.
The button should redirect to:
https://www.google.com/search?q=site:yourforum.com+YOUR_QUERY
where YOUR_QUERY is dynamically replaced with the user’s input.
- Use a Plugin (Backend Approach)
A Discourse plugin could be developed to:
Query Google Search API alongside Discourse’s own search.
Merge results from both sources.
Display them in the search results dropdown or page.
This would require:
Access to the Google Custom Search API (paid if high-volume).
Modifying Discourse’s search controller to send dual queries.
Customizing the UI to display Google results alongside Discourse ones.
- Redirect Unsuccessful Searches to Google
Another quick workaround:
If no Discourse search results are found, show a "Try searching on Google" link.
Clicking it would redirect users to a Google search with site:yourforum.com.
Then:
Would you like help with code for a theme modification or guidance on a plugin?
You said:
Yes please
ChatGPT said:
Here’s how you can modify your Discourse theme to add a “Search with Google” button inside the search bar.
Steps to Add a “Search with Google” Button in Discourse Search
Go to Admin → Customize → Themes
Create a new Theme Component (or edit an existing one).
Add the following code to the Header (Common) section under "Edit CSS/HTML":
JavaScript (to modify the search bar UI)
Go to the “Header” section and add this:
<p>No results found. <a href="https://www.google.com/search?q=site:{{window.location.hostname}}+{{searchTerm}}" target="_blank">Try searching on Google?</a></p>
{{/if}}
How It Works
This script adds a "Google Search" button inside the Discourse search bar.
When clicked, it opens a Google search with site:yourforum.com applied.
Users can still use the native Discourse search alongside this.
Alternative: Show a Google Search Link When No Results Are Found
If you want to show a “Search on Google” link when no Discourse results appear, modify the search_results.hbs template in a Theme Component like this:
{{#if no_results}}
No results found. Try searching on Google?
{{/if}}
This approach doesn’t require plugins and is easy to apply. Would you like any additional customization? 