Site Search

  • Subscribe to our RSS feed.
  • Twitter
  • StumbleUpon
  • Reddit
  • Facebook
  • Digg

Monday, 10 August 2009

Custom Search with Style like Peanut Butter with Jelly

Posted on 11:54 by Unknown
Posted by: Jeff Scudder, Developer Programs Engineer

Creating a custom look and feel for your website can have significant benefits in everything from improving usability to setting a professional or playful tone for your website. In many cases, letting users search the content of your site and related sites gets them the information they need faster. After all, a speedy user experience is a happy user experience. Here are some examples of how Custom Search and custom styles are as easy (and delicious) as peanut butter and jelly.

We start with a Custom Search Element, which uses the CustomSearchControl to add Custom Search to my web page. If you've never used a Custom Search engine before, I think you'll find a lot to love: it uses Google's search technology to include a specific group of websites for indexing, and you can share in ad revenue.



One of the many benefits of using the AJAX Search APIs to dynamically add search capabilities to your web pages is that you can also control the look and feel of the search input and results by using open web standards like cascading style sheets (CSS). When you combine this styling with Custom Search, you can create a seamless search experience for your users.

You can begin by changing the search input box (dynamically added to your page by default) to use an input box that you've placed on the page wherever you like.
// Set drawing options to use my text box
// as input instead of having the library create one.
var drawOptions = new google.search.DrawOptions();
drawOptions.setInput(document.getElementById('query_input'));

// Draw the control in content div
customSearchControl.draw('results', drawOptions);
With the above changes we get a page that looks like this:

Now that we're able to use a Custom Search box (look ma, no button push required!) we can add CSS rules to change fonts, colors, and more in the search results.

For example, see: http://ajax-apis.appspot.com/cse-style which has CSS rules that effect the styling of the search results and compare it to our first step which uses the default styles.

Take a look at the CSS rules to get an idea for how this works, and how you can do custom styling to fit your own website.

We can change the font and add a border around each search result:
#results .gsc-results {
/* Sets font for titles, snippets, and URLs. */
font-family: arial, helvetica, sans-serif;
}

#results .gsc-result {
position: relative;
border: 1px solid #eee;
border-left: 10px solid #eee;
padding: 8px 8px 8px 20px;
border-radius: 8px;
-webkit-border-radius: 8px;
-moz-border-radius: 8px;
}
We can also change the style of a single result when the user moves the mouse cursor over it:
#results .gsc-result:hover {
border: 1px solid #888;
border-left: 10px solid #888;
}


These are just a couple of examples. Since the CSS styling is handled by the browser, you can use any supported CSS rules to select portions of the search results. For more information on the result HTML structure and the CSS classes you may want to select in your own customizations, see the documentation on styling AJAX Search results.
Read More
Posted in | No comments
Newer Posts Older Posts Home
Subscribe to: Comments (Atom)

Popular Posts

  • Custom Search Engine APIs
    Posted by: Matt Wytock, Software Engineer A couple of weeks ago we blogged about a new feature and a new kind of Custom Search Engine (CS...
  • Connecting with the Adobe Community with Google Site Search
    Posted by: Tom Duerig, Software Engineer We love Google Site Search. And when working with our customers, we often discover new and interest...
  • Autocompletion of queries in Custom Search
    One of the most requested features for Custom Search is autocompletion of queries. Today, we announced at Google I/O that you can now enab...
  • Star Power
    Posted by: Jay Davies, Community Manager If you've created a Custom Search Engine you've likely encountered the term 'URL patter...
  • Ads background colors in Custom Search
    As we continue to improve the look and feel of Google Custom Search Engine (CSE), today we’re announcing a change in how ads are displayed ...
  • Ads now in harmony with search results
    Posted by: Tom Duerig, Software Engineer Many folks have pointed out that all the results on the page -- both the search results and the adv...
  • Bootstrapping your CSEs from keywords
    Custom Search provides upto 5000 URL patterns to define a “slice” of the web to search over. However, if you’re creating a Custom Search Eng...
  • Integrating Custom Search with your service
    Posted by: Kevin Gollum Lim, Technical Writer Most people who need something just go to the store to get the item, but a number of people ta...
  • Custom Search at the core of Google Site Search
    Posted by: Matt Wytock and Vrishali Wagle, Software Engineers Today, we announced Google Site Search , a hosted website search product that...
  • Custom Search promotions made easier
    Posted by: Bartlomiej Niechwiej and Nicholas Weininger, Software Engineers Last year, we made it easier to promote relevant information to ...

Blog Archive

  • ►  2013 (5)
    • ►  December (1)
    • ►  October (1)
    • ►  September (1)
    • ►  March (1)
    • ►  January (1)
  • ►  2012 (8)
    • ►  August (1)
    • ►  June (1)
    • ►  May (1)
    • ►  March (1)
    • ►  February (2)
    • ►  January (2)
  • ►  2011 (18)
    • ►  December (2)
    • ►  November (4)
    • ►  October (1)
    • ►  September (2)
    • ►  August (1)
    • ►  July (1)
    • ►  June (3)
    • ►  April (1)
    • ►  March (1)
    • ►  February (1)
    • ►  January (1)
  • ►  2010 (14)
    • ►  December (1)
    • ►  November (2)
    • ►  October (1)
    • ►  September (1)
    • ►  August (1)
    • ►  May (1)
    • ►  April (3)
    • ►  March (2)
    • ►  February (1)
    • ►  January (1)
  • ▼  2009 (23)
    • ►  December (1)
    • ►  November (1)
    • ►  October (6)
    • ►  September (1)
    • ▼  August (1)
      • Custom Search with Style like Peanut Butter with J...
    • ►  July (2)
    • ►  June (2)
    • ►  May (5)
    • ►  April (1)
    • ►  March (1)
    • ►  February (1)
    • ►  January (1)
  • ►  2008 (18)
    • ►  December (1)
    • ►  November (1)
    • ►  October (2)
    • ►  September (3)
    • ►  August (1)
    • ►  June (2)
    • ►  May (1)
    • ►  April (1)
    • ►  March (3)
    • ►  February (2)
    • ►  January (1)
  • ►  2007 (20)
    • ►  December (1)
    • ►  November (1)
    • ►  October (1)
    • ►  September (2)
    • ►  August (1)
    • ►  July (2)
    • ►  June (3)
    • ►  May (1)
    • ►  April (1)
    • ►  March (2)
    • ►  February (3)
    • ►  January (2)
  • ►  2006 (9)
    • ►  December (2)
    • ►  November (7)
Powered by Blogger.

About Me

Unknown
View my complete profile