Source:
private void doTitlePrefixSearch(final String searchTerm, boolean force) { cancelSearchTask(); final long startTime = System.nanoTime(); updateProgressBar(true); disposables.add(Observable.timer(force ? 0 : DELAY_MILLIS, TimeUnit.MILLISECONDS).flatMap(timer -> Observable.zip(ServiceFactory.get(WikiSite.forLanguageCode(getSearchLanguageCode())).prefixSearch(searchTerm, BATCH_SIZE, searchTerm), (searchTerm.length() > 2) ? Observable.fromCallable(() -> ReadingListDbHelper.instance().findPageForSearchQueryInAnyList(currentSearchTerm)) : Observable.just(new SearchResults()), (searchTerm.length() > 2) ? Observable.fromCallable(() -> HistoryDbHelper.INSTANCE.findHistoryItem(currentSearchTerm)) : Observable.just(new SearchResults()), (searchResponse, readingListSearchResults, historySearchResults) -> { SearchResults searchResults; if (searchResponse != null && searchResponse.query() != null && searchResponse.query().pages() != null) { searchResults = new SearchResults(searchResponse.query().pages(), WikiSite.forLanguageCode(getSearchLanguageCode()), searchResponse.continuation(), searchResponse.suggestion()); } else { searchResults = new SearchResults(); } handleSuggestion(searchResults.getSuggestion()); List<SearchResult> resultList = new ArrayList<>(readingListSearchResults.getResults()); resultList.addAll(historySearchResults.getResults()); addSearchResultsFromTabs(resultList); resultList.addAll(searchResults.getResults()); return resultList; })) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .doAfterTerminate(() -> updateProgressBar(false)) .subscribe(results -> { searchErrorView.setVisibility(GONE); handleResults(results, searchTerm, startTime); }, caught -> { searchErrorView.setVisibility(VISIBLE); searchErrorView.setError(caught); searchResultsContainer.setVisibility(GONE); logError(false, startTime); })); }

Target:
private void doTitlePrefixSearch(final String searchTerm, boolean force) { cancelSearchTask(); final long startTime = System.nanoTime(); updateProgressBar(true); disposables.add(Observable.timer(force ? 0 : DELAY_MILLIS, TimeUnit.MILLISECONDS).flatMap(timer -> Observable.zip(ServiceFactory.get(WikiSite.forLanguageCode(getSearchLanguageCode())).prefixSearch(searchTerm, BATCH_SIZE, searchTerm), (searchTerm.length() >= 2) ? Observable.fromCallable(() -> ReadingListDbHelper.instance().findPageForSearchQueryInAnyList(currentSearchTerm)) : Observable.just(new SearchResults()), (searchTerm.length() >= 2) ? Observable.fromCallable(() -> HistoryDbHelper.INSTANCE.findHistoryItem(currentSearchTerm)) : Observable.just(new SearchResults()), (searchResponse, readingListSearchResults, historySearchResults) -> { SearchResults searchResults; if (searchResponse != null && searchResponse.query() != null && searchResponse.query().pages() != null) { searchResults = new SearchResults(searchResponse.query().pages(), WikiSite.forLanguageCode(getSearchLanguageCode()), searchResponse.continuation(), searchResponse.suggestion()); } else { searchResults = new SearchResults(); } handleSuggestion(searchResults.getSuggestion()); List<SearchResult> resultList = new ArrayList<>(readingListSearchResults.getResults()); resultList.addAll(historySearchResults.getResults()); addSearchResultsFromTabs(resultList); resultList.addAll(searchResults.getResults()); return resultList; })) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .doAfterTerminate(() -> updateProgressBar(false)) .subscribe(results -> { searchErrorView.setVisibility(GONE); handleResults(results, searchTerm, startTime); }, caught -> { searchErrorView.setVisibility(VISIBLE); searchErrorView.setError(caught); searchResultsContainer.setVisibility(GONE); logError(false, startTime); })); }