My favorites | English | Sign in

Google Custom Search APIs and Tools

Improving User Queries for More Relevant Results

The Helping Your Users Refine Their Searches page showed you how you can create refinement labels that helps your users get more targeted results. This page will show you how to change or respond to your users' queries to deliver results that are more relevant.

Contents

This page includes the following sections:

Overview

If you know your audience well, you can roughly predict the kinds of things they might search for. You can anticipate their queries and help them find more relevant results.

Custom Search enables you append search terms to your users' queries, redirect users to another website or search engine, and create synonyms of your users' queries. The first two features are implemented through refinements, which your users can apply or ignore; while the synonym features act on your users' queries without requiring any user action.

Appending Search Queries with Refinement Labels

If you want to help your users by providing refinement links that add helpful search terms to their queries, you can use the Rewrite element in your refinements. The element appends the search terms to your users' queries when they click a refinement link. The Rewrite element can have up to 100 characters, all of which should be lowercase, except for uppercase search operators such as OR. To learn more about search operators, see the Advanced Search Made Easy page. To learn more about refinements, see Helping Your Users Refine Their Searches.

The following example shows you how you can use Rewrite.

<CustomSearchEngine>
   <Title>Universities</Title>

   <Context>

     <Facet>
        <FacetItem title="Homework">
          <Label name="assignments" mode="BOOST">
            <Rewrite>homework OR assignment</Rewrite>
         </Label>
       </FacetItem>
     </Facet>
   </Context>

</CustomSearchEngine>

The example shows how to help users who click the refinement link called "Homework". It appends additional search terms, "homework" and "assignment", to the search query that your users typed.

A refinements with the Rewrite element has the following structure:

  • Facet
    • FacetItem (up to four)
      • Label name
        • Rewrite

Back to top

Redirecting Search Queries with Refinement Labels

If you want to redirect your users to a different website when they click on a refinement link, you can use the Redirect element's url attribute, as in the following example.

<CustomSearchEngine>
   
<Title>Universities</Title>
   
<Context>
     
<Facet>
     
<FacetItem title="Papers">
       
<Label name="papers" mode="FILTER"/>
       
<Redirect url="http://scholar.google.com/scholar?q=$q"/>    
     
</FacetItem>
     
</Facet>
   
</Context>
</CustomSearchEngine>

In the example, users are redirected to another search engine, http://scholar.google.com/scholar. The latter part of the URL, ?q=, is the parameter for entering queries for Google Scholar. The parameter value in last part, $q echoes your users' queries.

If your URL has CGI arguments, use &amp; instead of &.

A refinements with the Redirect element has the following structure:

  • Facet
    • FacetItem (up to four)
      • Label name
      • Redirect

Note: Redirect is a child element of FacetItem, not Label.

Back to top

Expanding Search Queries with Synonyms

You can expand your users' search queries by using synonyms, which are variants of a search term. For example, the finance-related search query,"interest", could have the following equivalent alternatives: "yield", "dividend", "coupon", and so on. If you create synonyms for "interest" in your financial search engine, your users will not need to type multiple variants to find information they are seeking. The custom search engine will automatically search for all sites that are relevant to "interest", "yield", "dividend","coupon", and other related terms.

A search term with synonyms you defined automatically triggers a search expansion, whether or not the user enters the search term on its own or along with a series of other words. Let's say, you've defined "ninja" as a search term with the synonym variant, "assassin". Any search query that includes the word "ninja"—such as just "ninja" alone or "ninja hotdog eating contest"—would expand the query to include the synonymous variants. It is as though the user had searched for "ninja OR assassin" or "ninja OR assassin hotdog eating contest".

Following Best Practices

Popular query terms, common initialisms (such as "CD" for "certificate of deposit"), and familiar abbreviations (such as "munis" for "municipal bonds") that are idiosyncratic to your specialized field or interest are great candidates for having synonyms. If your search engine is popular enough and receives many searches for the same queries, you can get data about your most popular queries from the statistics page. Go to My Search Engine and click the statistics link for the search engine. Popular queries are listed at the bottom of the page.

Don't bother creating synonyms for query terms that are common to the general public. For example, the synonymous terms "UK", "Britain", "United Kingdom", "United Kingdom of Great Britain" are fairly well-known variants to most web users. Google already has a large body of synonyms for such terms, and since Custom Search lets you harness many of the search features of Google search, you shouldn't bother replicating the work.

Instead, create synonyms for common terms that are specific to the interests of the users of your search engine. For example, in the financial search engine, "bond" would be a great candidate. Unlike you, Google search might not know the context under which your users are searching. They could be looking for "James Bond", "chemical bond", "adhesive bond", "emotional bond", or whatnot. You, on the other hand, know that they are looking for a financial instrument and can easily come up with synonyms such as "fixed-income security" and "issue".

If you cannot discern whether a term is common or idiosyncratic, you can test the term and its variants on Google search. Type the query term (such as "san francisco") on Google search and then open a new browser window. In the Google search box, type the query term, the search operator OR, and the variant of the query term (for example, "san francisco OR sf"). Compare the two results pages. If they are exactly the same, then Google has the synonymous terms covered.

Creating Synonyms

Unlike other Custom Search features, you create the XML for synonyms not in the context file nor the annotations file, but in its own file. As with any XML file, you can use a simple text editor to create and edit the synonyms file. Just save the text file with the file extension .xml (for example, cse_syn_finance.xml).

The following is an example of a synonyms file:

   <Synonyms>
     
<Synonym term="stock">
       
<Variant>equity</Variant>
       
<Variant>share</Variant>
     
</Synonym>
     
<Synonym term="bond">
       
<Variant>fixed-income security</Variant>
       
<Variant>issue</Variant>
       
<Variant>high yield debt</Variant>
     
</Synonym>
   
</Synonyms>

A synonyms file has one element and one child element that can have multiple siblings, as described in the following hierarchy:

  • Synonyms (1 only)
    • Synonym term (multiple siblings allowed)
      • Variant (up to 10 for each Synonym)

You create the search term in the attribute value of the Synonym child element and define each of its synonyms in the Variant element. The search term and its synonym variants could be a single word (such as, "cookie") or phrases (such as "buttermilk cookie" or "crying over spilled milk").

If you are programmatically uploading synonyms using HTTP methods, you have to use additional elements that tell the Custom Search API what to do with the synonyms, such as whether they should be added or removed. For more information, see Programmatically Creating Custom Search Engines.

Following the Limits

The following table lists the limits for synonym files:

Item Maximum allowed
Number of search terms (Synonym term element) Multiple search terms, so long as the total number of variants do not exceed 500 for each search engine.
Number of variants (Variant elements) for each search term 10

 

Total number of variants (Variant elements) for the search engine 500
File size 500 kb
Number of files As many as you need, so long as the aggregate size of all files in the account does not exceed 4 mb

Back to top

Autocompleting Queries

Autocompletion is a list of optional queries that appear as users type their queries.

Figure 1: Typing just a few characters in the search box brings up a drop-down list that provides options for different search queries.

Typing "p-u-e-r" in a custom search engine for a travel site brings up a drop-down list with options for "puerto rico", "puerto vallarta hotels", "puerto vallarta vacations" and so on.

The list of optional queries used for autocompletion is derived partly from the contents of the website and the popularity of the query term. However, you can customize autocompletion by adding or removing terms from it, either in the control panel or through a bulk upload in an XML file.

To enable autocompletion in search engines using the Search Element or iframe, do the following:

Enabling Autocompletions

  1. In the control panel, click the Autocompletions section.
  2. Select the Enable autocompletions check box.
  3. Click Save Changes.
  4. Click the Get code tab and copy the generated code snippet, and insert it your webpage.

You can either add or remove individual terms in the Autocompletions section of the control panel or upload all the terms using an XML. The terms that you add appear above the algorithmically generated terms for all queries.

It might take up to two hours before autocompletion terms start appearing in your search engine.

If you want to add or remove terms in bulk, you can upload an autcompletions XML file. Unlike other Custom Search features, you create the XML for autocompletions not in the context file nor the annotations file, but in its own file. As with any XML file, you can use a simple text editor to create and edit the synonyms file. Just save the text file with the file extension .xml (for example, cse_autocompletion_finance.xml).

Adding and Removing Autocompletion Terms

The following is an example of a autocompletions file that you can upload.

<Autocompletions>
 
<Autocompletion term="cake" type="1" language=""/>
 
<Autocompletion term="strawberry.*" type="2" match="2" language=""/>
 
<Autocompletion term="vanilla" type="2" language=""/>
</Autocompletions>

In the sample code, "cake" is included in the list of possible autocompletion terms, whereas "vanilla" and any term starting with "strawberry" will never be presented to the user as an autocompletion term.

An automcompletion file has one element and one child element that can have multiple siblings, as described in the following hierarchy:

  • Autocompletions (1 only)
    • Autocompletion (multiple siblings allowed)

The following table lists the autcompletion attrbute names.

Attribute name Description Value
term The individual term or regular expression to include or exclude. Autocompletion term to include or exclude. For example, if you want to add "storm shadow" to the list of autocompletion terms presented to your users, add "storm shadow" as the value. Note that using the same term in multiple Autocompletion entries will result in an error..
type Specify whether the term should be included or excluded from the autocompletion. Specify either:
  • 1 - add a term (whitelist).
  • 2 - remove a term (blacklist).
  • match Optional. Specify whether you want the term to be matched exactly or with regular expression. Specify either:
  • 1 - Default. Exact match.
  • 2 - for Regular expression. Only blacklists can have regular expression.
  • language Optional. Restrict the autocompletion to a specific language. Leave this undefined, because, by default, Custom Search uses the language you have defined on the Basics section of the control panel.

    Back to top

    Taking the Next Step

    If you want to promote certain webpages or directly answer questions of your users, you can create special results. But if you are done creating tools for your search engine, you can start designing its look and feel.

    < Back to Helping Your Users Refine Their Searches | Forward to Creating Special Results >