Example usage for com.google.gwt.search.client WebSearch setSiteRestriction

List of usage examples for com.google.gwt.search.client WebSearch setSiteRestriction

Introduction

In this page you can find the example usage for com.google.gwt.search.client WebSearch setSiteRestriction.

Prototype

public void setSiteRestriction(String site) 

Source Link

Document

This method is used to restrict the set of web search results returned by this searcher.

Usage

From source file:com.appspot.socialinquirer.client.activity.HomeActivity.java

License:Apache License

@Override
public void onQuestionsSearchPerformed(final String text) {
    GWT.runAsync(new RunAsyncCallback() {
        public void onFailure(Throwable caught) {
            Window.alert("Code download failed");
        }//  ww w .  j  a v  a 2s  .com

        public void onSuccess() {
            SearchControlOptions options = new SearchControlOptions();

            WebSearch ws = new WebSearch();
            ws.setSiteRestriction("015203706368483719477:w4zebhpqxyu");
            options.add(ws);
            SearchControl searchControl = new SearchControl(options);
            searchControl.addSearchResultsHandler(new SearchResultsHandler() {

                @Override
                public void onSearchResults(SearchResultsEvent event) {
                    JsArray<? extends Result> results = event.getResults();
                    ArrayList<Question> questions = new ArrayList<Question>();
                    for (int i = 0; i < results.length(); i++) {
                        Result result = results.get(i);
                        if (result instanceof WebResult) {
                            Question question = createQuestion((WebResult) result);
                            question.setKey(getQuestionId(((WebResult) result).getUnescapedUrl()));
                            if (question.getKey() != null) {
                                questions.add(question);
                            }
                        }
                    }
                    homeView.setQuestions(questions);
                }

            });
            searchControl.execute(text);
        }
    });

}

From source file:com.google.gwt.search.sample.hellosearch.client.HelloSearch.java

License:Apache License

public void onApiLoad() {
    SearchControlOptions options = new SearchControlOptions();

    // We can use custom subclasses
    options.add(new GoogleCodeWebSearch(), ExpandMode.OPEN);

    // Or configure inline
    WebSearch ws = new WebSearch();
    ws.setSiteRestriction("ajaxian.com");
    ws.setUserDefinedLabel("Ajaxian");
    ws.setResultSetSize(ResultSetSize.SMALL);
    options.add(ws);// ww  w .  ja v a2 s  .  c  o m
    options.add(new BookSearch());
    options.add(new NewsSearch());
    options.add(new VideoSearch(), ExpandMode.CLOSED);
    options.add(new ImageSearch());
    options.setKeepLabel(KeepLabel.SAVE);
    options.setLinkTarget(LinkTarget.BLANK);

    SearchControl searchControl = new SearchControl(options);
    searchControl.addKeepHandler(this);
    searchControl.addSearchResultsHandler(this);
    searchControl.addSearchStartingHandler(this);
    searchControl.execute("Google Web Toolkit");
    hp.add(searchControl);
}