how to add Refine search results in Google Ajax API search

38 views
Skip to first unread message

MD

unread,
Mar 9, 2007, 6:19:15 AM3/9/07
to Google AJAX Search API
I want to integrate the Refine search in Google Ajax API search. This
feature is easily available in Google Custom search. It is generally
displayed at top of the search result. This feature provides us to
fast search for the specified keywords declared in the Refine search
section.
Please let me know if any one has solution on this topic.

VisualD...@gmail.com

unread,
Mar 9, 2007, 10:30:34 AM3/9/07
to Google AJAX Search API
This is tricky. You can set the site restriction of a GwebSearch to a
CSE id, and force it to use the results from that custom search
engine. Adding a second parameter to the setSiteRestriction call, you
can force a search to match a given refinement within your CSE. I
have an example up at: http://www.visualdxhealth.com/cseTest.htm The
first tab is general results from the CSE, the next three are
refinement specific. The first two refinement labels are
"condition_symptoms" and "condition_treatment". I haven't attached
these labels to any sites in my CSE, but they are used by Google
Health as standard refinements, and I have attached search terms to
them, which helps to tailor the results ("condition_treatment" adds
"treatment OR therapy OR cure" to the query). The last refinement
matches only one URL pattern in the CSE, "www.visualdxhealth.com/adult/
*" (sites about adult health issues on our website). Try searches for
"joint pain" and "acne" to see how the refinements alter the results.

This isn't exactly what you asked for, but it's a start. If you want
some functionality that more closely mirrors the Custom Search, you
could have a table of links at the top of your search page that has a
link for each of the refinements in your CSE, and a single
GwebSearch. When a user clicks one of the refinement links, call
setSiteRestriction on your GwebSearch with the appropriate label and
then execute the GsearchControl that contains it.

HTH,

--James

MD

unread,
Mar 15, 2007, 2:11:32 AM3/15/07
to Google AJAX Search API
Hello, I have created the table at the top of the search with the
fields that are required for my refine search.
But, I am not sure that the way I am going to get the results for the
refine search. I am briefly explaining my code below...

function cse(SearchExpression) {
var sFormDiv = document.getElementById("searchForm");
var leftScDiv = document.getElementById("leftSearchControl");

// create a left, right search control
// create a custom search form
this.leftControl = new GSearchControl();
this.searchForm = new GSearchForm(true, sFormDiv);

var searcher;
var options;

// configure left control
// Site Restrict to CSE ID for Search
var cseId = my cseid goes here...;
searcher = new GwebSearch();
options = new GsearcherOptions();
searcher.setSiteRestriction(cseId, searchExpression);
options.setExpandMode(GSearchControl.EXPAND_MODE_OPEN);
this.leftControl.addSearcher(searcher, options);

...
...
...
}
function OnLoad() {
new cse("");
}
function RefineSearch(SearchExpression) {
new cse(SearchExpression);
}


One of the field from HTML table for refine search ...
<a href="javascript:RefineSearch('XYZ');">XYZ</a>


What should I call on the click of the refine search field? I tried to
call the cse() function on the click by passing the value for the
refine search, but it just clears the search input box and nothing is
displayed.
Could it possible for you to explain the same (if possible with the
code) so that i can correct my self on that?

VisualDxHealth Logical Images

unread,
Mar 16, 2007, 10:57:28 AM3/16/07
to Google-AJAX...@googlegroups.com
I have an example of how you might do something like this running here: http://www.visualdxhealth.com/cseTest2.htm
 
This is really just another way to display results in tabs (only this time there's only one GwebSearch, instead of one for each tab).
 
If you want to be able to support the ability to clear refinements, it looks like you'll have to have another GwebSearch that has its siteRestriction set to the vanilla CSE, because after you apply a refinement ".setSiteRestriction(cseId, refinement)" to a GwebSearch it doesn't seem like you can just call ".setSiteRestriction(cseId)" to have it search against the CSE without refinements.
 
The relatively recent changes to the "more results" link at the end of the search results is handy, as it sends users to your CSE page, and it remembers which refinement you have selected.  If you don't want to send users to your default CSE homepage, you can change the page users are directed to by specifying a third parameter when you call setSiteRestriction.
 
If you want to support multiple refinements at once, you could do it by keeping track of which refinements have been selected, and adding them to the end of a search query before calling execute(query) on your GSearchControl.  For example, searching for the query "diabetes more:condition_treatment more:condition_symptoms" in my CSE applys both of the refinements "condition_treatment" and "condition_symptoms".
 
--James
 
On 3/15/07, MD <mdh...@encodexindia.com> wrote:

Hello, I have created the table at the top of the search with the
fields that are required for my refine search.
But, I am not sure that the way I am going to get the results for the
refine search. I am briefly explaining my code below...

function cse(SearchExpression) {
       var sFormDiv = document.getElementById ("searchForm");
Reply all
Reply to author
Forward
0 new messages