/customsearch/community?hl=en
/customsearch/community?hl=en
6/29/11
Original Poster
rs2010

Can you set a specific refinement label as the default result set?

Hi, i'm wondering if it's possible to set a refinement label as the default result listing? For example, a user enters a query on a Google CS that has two refinement labels. Currently the search will load the results of both, but i want to load just the results of one by default, and have the other label there as another option for users who may be looking for something else.

thanks!
Community content may not be verified or up-to-date. Learn more.
All Replies (7)
cosgcomm
7/15/11
cosgcomm
I have the exact same question. Hopefully an answer will be posted soon!
Jcmesserschmidt
10/19/11
Jcmesserschmidt
Google user
11/28/11
Google user
Although it's undocumented by Google on this page:
http://code.google.com/intl/en/apis/customsearch/docs/js/cselement-reference.html

I looked through the JavaScript source file and found it IS possible ( see below ).

This will set the default refinement label, and change the tab. Perfecto!
var searchOps = {'defaultToRefinement': 'my_refinement_label'};
var searcher = new google.search.CustomSearchControl('[Custom Search ID]', searchOps);


hxu-cse
12/1/11
hxu-cse
Wow! You guys rock! Yes, setting the default refinement label hasn't been documented yet (we are working on a more complete Element documentation including this), and it can be done exactly as you discovered.
toyNN
12/3/11
toyNN
Nice - I've been searching around for just this ability to change the default search refinement label. Excellent and works perfectly and appears to semi-officially indorsed as a preferred method. Thanks for posting!

Here is the code I used for a results only page that's calling another function to parse the search query,

   google.load('search', '1', { language: 'en' });
    google
.setOnLoadCallback(function () {
       
var searchOps = { 'defaultToRefinement': 'my_refinement_label' };
       
var customSearchControl = new google.search.CustomSearchControl('My CSE ID', searchOps);
        customSearchControl
.setResultSetSize(google.search.Search.FILTERED_CSE_RESULTSET);
       
var options = new google.search.DrawOptions();
        options
.enableSearchResultsOnly();
        customSearchControl
.draw('cse', options);
       
var queryFromUrl = parseQueryFromUrl();
       
if (queryFromUrl) {
            customSearchControl
.execute(queryFromUrl);
       
}
   
}, true);


hxu-cse
2/9/12
hxu-cse
And that option is documented now:
cregox
5/14/17
cregox
@hxu-cse is still right! :) 😄search for "defaultToRefinement" and, today, it brought me to https://developers.google.com/custom-search/docs/elementand I've used it as this, on my page's code:<gcse:search defaultToRefinement="main"></gcse:search>now, wished I knew how to keep the formatting here!2
 
This question is locked and replying has been disabled. Still have questions? Ask the Help Community.

Badges

Some community members might have badges that indicate their identity or level of participation in a community.

 
Expert - Google Employee — Googler guides and community managers
 
Expert - Community Specialist — Google partners who share their expertise
 
Expert - Gold — Trusted members who are knowledgeable and active contributors
 
Expert - Platinum — Seasoned members who contribute beyond providing help through mentoring, creating content, and more
 
Expert - Alumni — Past members who are no longer active, but were previously recognized for their helpfulness
 
Expert - Silver — New members who are developing their product knowledge
Community content may not be verified or up-to-date. Learn more.

Levels

Member levels indicate a user's level of participation in a forum. The greater the participation, the higher the level. Everyone starts at level 1 and can rise to level 10. These activities can increase your level in a forum:

  • Post an answer.
  • Having your answer selected as the best answer.
  • Having your post rated as helpful.
  • Vote up a post.
  • Correctly mark a topic or post as abuse.

Having a post marked and removed as abuse will slow a user's advance in levels.

View profile in forum?

To view this member's profile, you need to leave the current Help page.

Report abuse in forum?

This comment originated in the Google Product Forum. To report abuse, you need to leave the current Help page.

Reply in forum?

This comment originated in the Google Product Forum. To reply, you need to leave the current Help page.