Advanced search on Google Sites

Created by Romain Vialard

Enhance search on your site

By default, the search bar in Google Sites let's you search pages & documents on the site. But you can also create a custom search engine with Apps Script and add it to the Google Sites search bar.

IMAGES - TUTORIAL

Search results :

Tutorial

Here's an example where I let people search for files in a Drive folder:

Create the script

function doGet(e) {

var results = DriveApp.getFolderById('0B3xR7WfXrj7aQTc5NWNMOGtITGc').searchFiles('fullText contains "' + e.parameter.q + '"');

var app = UiApp.createApplication();

var panel = app.createVerticalPanel();

while(results.hasNext()) {

var file = results.next();

panel.add(app.createAnchor(file.getName(), file.getUrl()));

}

var scrollPanel = app.createScrollPanel(panel).setHeight(200);

app.add(scrollPanel);

return app;

}

The 'q' parameter is very important to trigger the search from Google Sites.

Embed this script in a Google Sites page

Create a page in your site and click on the menu Insert > Apps Script

This is not mandatory but it is better to show search results directly inside your site.

Add this search engine to your site

  1. Click on the menu More > Manage Site

  2. Click Configure Search, select the "Advanced" tab and choose the type "Google Search Appliance" as a Search Provider

  3. Then add the url of the page where your script is embedded as the search engine url.

  4. You have now a new search engine on your site