3

現在、私たちの組織は Google カスタム検索エンジンを使用して自動提案を提供しており、CSE で約 3 つの絞り込みラベルを構成しています。以前は、WebSearch と SearchControl を使用しており、WebSearch には絞り込みラベルを具体的に選択できる setSiteRestriction メソッドがあります: - http://code.google.com/apis/websearch/docs/reference.html#_class_GwebSearch

前のコード例:

var searchControl = new google.search.SearchControl();

var webSearch = new google.search.WebSearch();

//Refinement allows us to tell Google which specific sites to search
var refinement="Support";    
//filter custom search and currently there are 3 refinements
(some other variables declaration here including 'product')
switch(product)

{

    case "10000":
        refinement = "Support1";
        break;

    case "10200":
        refinement = "Support1";
        break;

    case "10001":
        refinement = "Support2";
        break;

    default:
        break;
}

/*this is the code to fill in the custom search. The refinement was set above - either "Support", "Support1", or "Support2".*/
webSearch.setSiteRestriction('cseId', refinement);
......  

ただし、現在、非推奨の WebSearch を置き換えるために CustomSearchControl ツールに移行していますが、switch case ステートメントの値に基づいて絞り込みラベルを具体的に選択する方法が見つからなかったようです。ここですぐに助けが必要です。関連するドキュメントがあれば、私に指摘していただければ幸いです。ありがとう!:)

4

2 に答える 2

3

customSearchControl を使用する場合、オプションで絞り込みラベルを設定できます。この意志

a) 検索の他の絞り込みを、(「more:」+絞り込み) で追加した可能性のあるキーワードに制限しない。

b) また、絞り込みタブを強調表示して、ユーザーに代わって何をしたかをユーザーに伝えます。

var customSearchOptions =
    { 'defaultToRefinement' : 'refinement_label_name' };

  var customSearchControl =
    new google.search.CustomSearchControl('YOUR_CSE_ID', customSearchOptions);

defaultToRefinement パラメータについては、カスタム検索要素JavaScript API リファレンスに記載されています。

以前、この回答はこちらで紹介されました。

于 2012-03-14T16:38:15.147 に答える
1

答えを得た。コードに次の行を追加しました。

var customSearchControl = new google.search.CustomSearchControl(cseId);
customSearchControl.setSearchStartingCallback(this, function(control, searcher, query) 
{
      searcher.setQueryAddition('more:' + refinement);
});
于 2011-05-28T13:49:34.317 に答える