@Test public void testEmptyResultsAreReturnedWhenNoIndexExists() { repository = searchRepositoryFactory.createRelatedItemSearchRepository(configuration,builder); SearchResultEventWithSearchRequestKey[] results = repository.findRelatedItems(configuration, createSearch()); assertEquals(2,results.length); System.out.println("testFailedResultsAreReturnedWhenNoIndexExists, Results 0 outcometype: " + results[0].getResponse().getOutcomeType()); System.out.println("testFailedResultsAreReturnedWhenNoIndexExists, Results 1 outcometype: " + results[1].getResponse().getOutcomeType()); assertSame(SearchResultsEvent.EMPTY_FREQUENTLY_RELATED_SEARCH_RESULTS, results[0].getResponse()); assertSame(SearchResultsEvent.EMPTY_FREQUENTLY_RELATED_SEARCH_RESULTS, results[1].getResponse()); }
@Override public SearchResultEventWithSearchRequestKey[] findRelatedItems(Configuration configuration, RelatedItemSearch[] searches) { log.debug("request to execute {} searches", searches.length); SearchResultEventWithSearchRequestKey[] results; HttpResult sr; long startNanos = System.nanoTime(); sr = frequentlyRelatedWithSearchBuilder.executeSearch(searches, elasticClient); HttpSearchExecutionStatus searchRequestStatus = sr.getStatus(); if (searchRequestStatus == HttpSearchExecutionStatus.OK) { log.debug("Processing results for search {} request(s)", searches.length); results = frequentlyRelatedWithSearchBuilder.processMultiSearchResponse(searches, sr); log.debug("Search Completed, returning processed results."); } else if (searchRequestStatus == HttpSearchExecutionStatus.REQUEST_FAILURE) { long time = (System.nanoTime() - startNanos) / 1000000; log.warn("Exception executing search request"); int size = searches.length; results = new SearchResultEventWithSearchRequestKey[size]; for (int i = 0; i < size; i++) { SearchRequestLookupKey key = searches[i].getLookupKey(); results[i] = new SearchResultEventWithSearchRequestKey(SearchResultsEvent.EMPTY_FAILED_FREQUENTLY_RELATED_SEARCH_RESULTS, key, time, searches[i].getStartOfRequestNanos()); } } else { long time = (System.nanoTime() - startNanos) / 1000000; if (searchRequestStatus == HttpSearchExecutionStatus.REQUEST_TIMEOUT) { log.warn("Request timeout executing search request"); } else { log.warn("Connection timeout executing search request"); } int size = searches.length; results = new SearchResultEventWithSearchRequestKey[size]; for (int i = 0; i < size; i++) { SearchRequestLookupKey key = searches[i].getLookupKey(); results[i] = new SearchResultEventWithSearchRequestKey(SearchResultsEvent.EMPTY_TIMED_OUT_FREQUENTLY_RELATED_SEARCH_RESULTS, key, time, searches[i].getStartOfRequestNanos()); } } return results; }
ElasticSearchRelatedItemHttpSearchRepository implements RelatedItemSearchRepository<FrequentlyRelatedSearchResult[]> { @Override public SearchResultEventWithSearchRequestKey[] findRelatedItems(Configuration configuration, RelatedItemSearch[] searches) { log.debug("request to execute {} searches", searches.length); SearchResultEventWithSearchRequestKey[] results; HttpResult sr; long startNanos = System.nanoTime(); sr = frequentlyRelatedWithSearchBuilder.executeSearch(searches, elasticClient); HttpSearchExecutionStatus searchRequestStatus = sr.getStatus(); if (searchRequestStatus == HttpSearchExecutionStatus.OK) { log.debug("Processing results for search {} request(s)", searches.length); results = frequentlyRelatedWithSearchBuilder.processMultiSearchResponse(searches, sr); log.debug("Search Completed, returning processed results."); } else if (searchRequestStatus == HttpSearchExecutionStatus.REQUEST_FAILURE) { long time = (System.nanoTime() - startNanos) / 1000000; log.warn("Exception executing search request"); int size = searches.length; results = new SearchResultEventWithSearchRequestKey[size]; for (int i = 0; i < size; i++) { SearchRequestLookupKey key = searches[i].getLookupKey(); results[i] = new SearchResultEventWithSearchRequestKey(SearchResultsEvent.EMPTY_FAILED_FREQUENTLY_RELATED_SEARCH_RESULTS, key, time, searches[i].getStartOfRequestNanos()); } } else { long time = (System.nanoTime() - startNanos) / 1000000; if (searchRequestStatus == HttpSearchExecutionStatus.REQUEST_TIMEOUT) { log.warn("Request timeout executing search request"); } else { log.warn("Connection timeout executing search request"); } int size = searches.length; results = new SearchResultEventWithSearchRequestKey[size]; for (int i = 0; i < size; i++) { SearchRequestLookupKey key = searches[i].getLookupKey(); results[i] = new SearchResultEventWithSearchRequestKey(SearchResultsEvent.EMPTY_TIMED_OUT_FREQUENTLY_RELATED_SEARCH_RESULTS, key, time, searches[i].getStartOfRequestNanos()); } } return results; } }
ElasticSearchRelatedItemHttpSearchRepository implements RelatedItemSearchRepository<FrequentlyRelatedSearchResult[]> { @Override public SearchResultEventWithSearchRequestKey[] findRelatedItems(Configuration configuration, RelatedItemSearch[] searches) { log.debug("request to execute {} searches", searches.length); SearchResultEventWithSearchRequestKey[] results; HttpResult sr; long startNanos = System.nanoTime(); sr = frequentlyRelatedWithSearchBuilder.executeSearch(searches, elasticClient); HttpSearchExecutionStatus searchRequestStatus = sr.getStatus(); if (searchRequestStatus == HttpSearchExecutionStatus.OK) { log.debug("Processing results for search {} request(s)", searches.length); results = frequentlyRelatedWithSearchBuilder.processMultiSearchResponse(searches, sr); log.debug("Search Completed, returning processed results."); } else if (searchRequestStatus == HttpSearchExecutionStatus.REQUEST_FAILURE) { long time = (System.nanoTime() - startNanos) / 1000000; log.warn("Exception executing search request"); int size = searches.length; results = new SearchResultEventWithSearchRequestKey[size]; for (int i = 0; i < size; i++) { SearchRequestLookupKey key = searches[i].getLookupKey(); results[i] = new SearchResultEventWithSearchRequestKey(SearchResultsEvent.EMPTY_FAILED_FREQUENTLY_RELATED_SEARCH_RESULTS, key, time, searches[i].getStartOfRequestNanos()); } } else { long time = (System.nanoTime() - startNanos) / 1000000; if (searchRequestStatus == HttpSearchExecutionStatus.REQUEST_TIMEOUT) { log.warn("Request timeout executing search request"); } else { log.warn("Connection timeout executing search request"); } int size = searches.length; results = new SearchResultEventWithSearchRequestKey[size]; for (int i = 0; i < size; i++) { SearchRequestLookupKey key = searches[i].getLookupKey(); results[i] = new SearchResultEventWithSearchRequestKey(SearchResultsEvent.EMPTY_TIMED_OUT_FREQUENTLY_RELATED_SEARCH_RESULTS, key, time, searches[i].getStartOfRequestNanos()); } } return results; } ElasticSearchRelatedItemHttpSearchRepository(Configuration configuration,
                                                        HttpElasticSearchClientFactory factory,
                                                        ElasticSearchFrequentlyRelatedItemHttpSearchProcessor builder); }
ElasticSearchRelatedItemHttpSearchRepository implements RelatedItemSearchRepository<FrequentlyRelatedSearchResult[]> { @Override public SearchResultEventWithSearchRequestKey[] findRelatedItems(Configuration configuration, RelatedItemSearch[] searches) { log.debug("request to execute {} searches", searches.length); SearchResultEventWithSearchRequestKey[] results; HttpResult sr; long startNanos = System.nanoTime(); sr = frequentlyRelatedWithSearchBuilder.executeSearch(searches, elasticClient); HttpSearchExecutionStatus searchRequestStatus = sr.getStatus(); if (searchRequestStatus == HttpSearchExecutionStatus.OK) { log.debug("Processing results for search {} request(s)", searches.length); results = frequentlyRelatedWithSearchBuilder.processMultiSearchResponse(searches, sr); log.debug("Search Completed, returning processed results."); } else if (searchRequestStatus == HttpSearchExecutionStatus.REQUEST_FAILURE) { long time = (System.nanoTime() - startNanos) / 1000000; log.warn("Exception executing search request"); int size = searches.length; results = new SearchResultEventWithSearchRequestKey[size]; for (int i = 0; i < size; i++) { SearchRequestLookupKey key = searches[i].getLookupKey(); results[i] = new SearchResultEventWithSearchRequestKey(SearchResultsEvent.EMPTY_FAILED_FREQUENTLY_RELATED_SEARCH_RESULTS, key, time, searches[i].getStartOfRequestNanos()); } } else { long time = (System.nanoTime() - startNanos) / 1000000; if (searchRequestStatus == HttpSearchExecutionStatus.REQUEST_TIMEOUT) { log.warn("Request timeout executing search request"); } else { log.warn("Connection timeout executing search request"); } int size = searches.length; results = new SearchResultEventWithSearchRequestKey[size]; for (int i = 0; i < size; i++) { SearchRequestLookupKey key = searches[i].getLookupKey(); results[i] = new SearchResultEventWithSearchRequestKey(SearchResultsEvent.EMPTY_TIMED_OUT_FREQUENTLY_RELATED_SEARCH_RESULTS, key, time, searches[i].getStartOfRequestNanos()); } } return results; } ElasticSearchRelatedItemHttpSearchRepository(Configuration configuration,
                                                        HttpElasticSearchClientFactory factory,
                                                        ElasticSearchFrequentlyRelatedItemHttpSearchProcessor builder); @Override SearchResultEventWithSearchRequestKey[] findRelatedItems(Configuration configuration,
                                                                    RelatedItemSearch[] searches); @Override void shutdown(); }
ElasticSearchRelatedItemHttpSearchRepository implements RelatedItemSearchRepository<FrequentlyRelatedSearchResult[]> { @Override public SearchResultEventWithSearchRequestKey[] findRelatedItems(Configuration configuration, RelatedItemSearch[] searches) { log.debug("request to execute {} searches", searches.length); SearchResultEventWithSearchRequestKey[] results; HttpResult sr; long startNanos = System.nanoTime(); sr = frequentlyRelatedWithSearchBuilder.executeSearch(searches, elasticClient); HttpSearchExecutionStatus searchRequestStatus = sr.getStatus(); if (searchRequestStatus == HttpSearchExecutionStatus.OK) { log.debug("Processing results for search {} request(s)", searches.length); results = frequentlyRelatedWithSearchBuilder.processMultiSearchResponse(searches, sr); log.debug("Search Completed, returning processed results."); } else if (searchRequestStatus == HttpSearchExecutionStatus.REQUEST_FAILURE) { long time = (System.nanoTime() - startNanos) / 1000000; log.warn("Exception executing search request"); int size = searches.length; results = new SearchResultEventWithSearchRequestKey[size]; for (int i = 0; i < size; i++) { SearchRequestLookupKey key = searches[i].getLookupKey(); results[i] = new SearchResultEventWithSearchRequestKey(SearchResultsEvent.EMPTY_FAILED_FREQUENTLY_RELATED_SEARCH_RESULTS, key, time, searches[i].getStartOfRequestNanos()); } } else { long time = (System.nanoTime() - startNanos) / 1000000; if (searchRequestStatus == HttpSearchExecutionStatus.REQUEST_TIMEOUT) { log.warn("Request timeout executing search request"); } else { log.warn("Connection timeout executing search request"); } int size = searches.length; results = new SearchResultEventWithSearchRequestKey[size]; for (int i = 0; i < size; i++) { SearchRequestLookupKey key = searches[i].getLookupKey(); results[i] = new SearchResultEventWithSearchRequestKey(SearchResultsEvent.EMPTY_TIMED_OUT_FREQUENTLY_RELATED_SEARCH_RESULTS, key, time, searches[i].getStartOfRequestNanos()); } } return results; } ElasticSearchRelatedItemHttpSearchRepository(Configuration configuration,
                                                        HttpElasticSearchClientFactory factory,
                                                        ElasticSearchFrequentlyRelatedItemHttpSearchProcessor builder); @Override SearchResultEventWithSearchRequestKey[] findRelatedItems(Configuration configuration,
                                                                    RelatedItemSearch[] searches); @Override void shutdown();  }