Example usage for com.google.gwt.search.client SearchControlOptions add

List of usage examples for com.google.gwt.search.client SearchControlOptions add

Introduction

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

Prototype

public void add(Search s) 

Source Link

Document

Add a Search to be executed by the SearchControl.

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");
        }//from   w  w  w  .j  av a 2  s  .c  o m

        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);
        }
    });

}