Example usage for com.google.gwt.search.client SearchResultsHandler SearchResultsHandler

List of usage examples for com.google.gwt.search.client SearchResultsHandler SearchResultsHandler

Introduction

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

Prototype

SearchResultsHandler

Source Link

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");
        }//w ww.j a  va  2  s  . c om

        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.mobile.trippy.web.client.db.DefaultSearchService.java

License:Apache License

/**
 * Google search related methods//from   w w w  .  ja v a  2 s .c o m
 */
private void doGoogleSearch(final String queryString, final HasLatLngBounds searchBounds,
        final String tripLocation, final SearchResultsListener listener) {

    googleSearchService.clearResults();
    googleSearchService.setNoHtmlGeneration();
    googleSearchService.setResultSetSize(ResultSetSize.LARGE);
    //    googleSearchService.setCenterPoint(searchBounds.getCenter().getJso());
    googleSearchService.setAddressLookupMode(AddressLookupMode.ENABLED);
    googleSearchService.setCenterPoint(tripLocation);

    final List<SearchItem> searchItemList = new ArrayList<SearchItem>();
    googleSearchService.addSearchResultsHandler(new SearchResultsHandler() {

        @SuppressWarnings("unchecked")
        @Override
        public void onSearchResults(SearchResultsEvent event) {
            JsArray<LocalResult> results = event.getResults().cast();
            if (results == null || results.length() == 0) {
                searchItemList.clear();
                listener.onSuccess(searchItemList);
                return;
            }
            addGoogleResultsToList(queryString, searchBounds, searchItemList, results);

            // for more than one page.
            final Cursor resultCursor = googleSearchService.getCursor();
            if (resultCursor != null) {
                int currentPage = resultCursor.getCurrentPageIndex();
                int totalPages = resultCursor.getPages().length();
                if (currentPage < totalPages - 1 && currentPage < MAX_GOOGLE_SEARCH_RESULTS_PAGE) {
                    googleSearchService.gotoPage(++currentPage);
                } else {
                    // Trippy-enforced page limit reached
                    searchResultsCache.put(getResultsCacheKey(SearchType.GOOGLE, queryString, searchBounds),
                            searchItemList);
                    listener.onSuccess(searchItemList);
                }
            } else {
                // No more results if cursor is null.
                searchResultsCache.put(getResultsCacheKey(SearchType.GOOGLE, queryString, searchBounds),
                        searchItemList);
                listener.onSuccess(searchItemList);
            }
        }
    });

    googleSearchService.execute(queryString);
}

From source file:next.celebs.api.API.java

License:Apache License

public void getPhotos(final Key searchKey, final int numberPages,
        final Response<JsArray<ImageResult>> response) {

    final SearchResultsHandler resultHandler = new SearchResultsHandler() {
        @Override// w  w w. j  av a 2  s.  co m
        public void onSearchResults(SearchResultsEvent event) {
            JsArray<ImageResult> data = (JsArray<ImageResult>) event.getResults();
            response.read(data);
        }
    };

    SearchUtils.loadSearchApi(new Runnable() {
        public void run() {
            ImageSearch search = initImageSearch(resultHandler);
            search.execute(searchKey.getSearchQuery());
            int[] page = { 1 };
            gotoPage(page, numberPages, search);
        }
    });
}

From source file:next.celebs.model.API.java

License:Apache License

public void getPhotos(final Key searchKey, final int numberPages,
        final Response<JsArray<ImageResult>> response) {

    final SearchResultsHandler resultHandler = new SearchResultsHandler() {
        @Override/*from  w  ww.j  av  a2 s  . c  om*/
        public void onSearchResults(SearchResultsEvent event) {
            @SuppressWarnings("unchecked")
            JsArray<ImageResult> data = (JsArray<ImageResult>) event.getResults();
            response.read(data);
        }
    };

    SearchUtils.loadSearchApi(new Runnable() {
        public void run() {
            ImageSearch search = initImageSearch(resultHandler);
            search.execute(searchKey.getSearchQuery());
            int[] page = { 1 };
            gotoPage(page, numberPages, search);
        }
    });
}