@Test public void testFindRelatedItems() throws Exception { try { server.indexDocument(configuration.getStorageIndexNamePrefix()+"-2013-12-14",RELATED_CONTENT_BLADES1_PURCHASEa); server.indexDocument(configuration.getStorageIndexNamePrefix()+"-2013-12-14",RELATED_CONTENT_BLADES1_PURCHASEb); server.indexDocument(configuration.getStorageIndexNamePrefix()+"-2013-12-15",RELATED_CONTENT_BLADES2_PURCHASEa); server.indexDocument(configuration.getStorageIndexNamePrefix()+"-2013-12-15",RELATED_CONTENT_BLADES2_PURCHASEb); server.indexDocument(configuration.getStorageIndexNamePrefix()+"-2013-12-15",RELATED_CONTENT_BLADES2_PURCHASEc); server.indexDocument(configuration.getStorageIndexNamePrefix()+"-2013-12-24",RELATED_CONTENT_THERAID_PURCHASEa); server.indexDocument(configuration.getStorageIndexNamePrefix()+"-2013-12-24",RELATED_CONTENT_THERAID_PURCHASEb); assertEquals(3,server.getIndexCount()); assertEquals(2,server.getDocCount(configuration.getStorageIndexNamePrefix()+"-2013-12-14")); assertEquals(3,server.getDocCount(configuration.getStorageIndexNamePrefix()+"-2013-12-15")); assertEquals(2,server.getDocCount(configuration.getStorageIndexNamePrefix()+"-2013-12-24")); } catch(Exception e) { fail("Cannot create test date for search test"); } RelatedItemSearch[] searches = createSearch(); SearchResultEventWithSearchRequestKey<FrequentlyRelatedSearchResult[]>[] results = repository.findRelatedItems(configuration, searches); assertEquals(2,results.length); assertNotSame(SearchResultsEvent.EMPTY_FAILED_FREQUENTLY_RELATED_SEARCH_RESULTS, results[0].getResponse()); assertNotSame(SearchResultsEvent.EMPTY_FAILED_FREQUENTLY_RELATED_SEARCH_RESULTS, results[1].getResponse()); assertNotSame(SearchResultsEvent.EMPTY_FREQUENTLY_RELATED_SEARCH_RESULTS, results[0].getResponse()); assertNotSame(SearchResultsEvent.EMPTY_FREQUENTLY_RELATED_SEARCH_RESULTS, results[1].getResponse()); assertNotSame(SearchResultsEvent.EMPTY_TIMED_OUT_FREQUENTLY_RELATED_SEARCH_RESULTS, results[0].getResponse()); assertNotSame(SearchResultsEvent.EMPTY_TIMED_OUT_FREQUENTLY_RELATED_SEARCH_RESULTS, results[1].getResponse()); assertEquals(1, results[0].getResponse().getSearchResults().length); assertEquals("blades of glory",results[0].getResponse().getSearchResults()[0].getRelatedItemId()); assertEquals("enter the dragon",results[1].getResponse().getSearchResults()[0].getRelatedItemId()); }
@Override public SearchResultEventWithSearchRequestKey[] findRelatedItems(Configuration configuration, RelatedItemSearch[] searches) { log.debug("request to execute {} searches",searches.length); SearchResultEventWithSearchRequestKey[] results; MultiSearchResponse sr; long startNanos = System.nanoTime(); try { sr = frequentlyRelatedWithSearchBuilder.executeSearch(elasticClient,searches); log.debug("Processing results for search {} request(s)",searches.length); results = frequentlyRelatedWithSearchBuilder.processMultiSearchResponse(searches,sr); log.debug("Search Completed, returning processed results."); } catch(ElasticsearchTimeoutException timeoutException) { long time = (System.nanoTime()-startNanos)/1000000; log.warn("Timeout exception executing search request: ",timeoutException); 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()); } } catch(Exception searchException) { long time = (System.nanoTime()-startNanos)/1000000; log.warn("Exception executing search request: ",searchException); 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()); } } return results; }
ElasticSearchRelatedItemSearchRepository implements RelatedItemSearchRepository<FrequentlyRelatedSearchResult[]> { @Override public SearchResultEventWithSearchRequestKey[] findRelatedItems(Configuration configuration, RelatedItemSearch[] searches) { log.debug("request to execute {} searches",searches.length); SearchResultEventWithSearchRequestKey[] results; MultiSearchResponse sr; long startNanos = System.nanoTime(); try { sr = frequentlyRelatedWithSearchBuilder.executeSearch(elasticClient,searches); log.debug("Processing results for search {} request(s)",searches.length); results = frequentlyRelatedWithSearchBuilder.processMultiSearchResponse(searches,sr); log.debug("Search Completed, returning processed results."); } catch(ElasticsearchTimeoutException timeoutException) { long time = (System.nanoTime()-startNanos)/1000000; log.warn("Timeout exception executing search request: ",timeoutException); 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()); } } catch(Exception searchException) { long time = (System.nanoTime()-startNanos)/1000000; log.warn("Exception executing search request: ",searchException); 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()); } } return results; } }
ElasticSearchRelatedItemSearchRepository implements RelatedItemSearchRepository<FrequentlyRelatedSearchResult[]> { @Override public SearchResultEventWithSearchRequestKey[] findRelatedItems(Configuration configuration, RelatedItemSearch[] searches) { log.debug("request to execute {} searches",searches.length); SearchResultEventWithSearchRequestKey[] results; MultiSearchResponse sr; long startNanos = System.nanoTime(); try { sr = frequentlyRelatedWithSearchBuilder.executeSearch(elasticClient,searches); log.debug("Processing results for search {} request(s)",searches.length); results = frequentlyRelatedWithSearchBuilder.processMultiSearchResponse(searches,sr); log.debug("Search Completed, returning processed results."); } catch(ElasticsearchTimeoutException timeoutException) { long time = (System.nanoTime()-startNanos)/1000000; log.warn("Timeout exception executing search request: ",timeoutException); 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()); } } catch(Exception searchException) { long time = (System.nanoTime()-startNanos)/1000000; log.warn("Exception executing search request: ",searchException); 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()); } } return results; } ElasticSearchRelatedItemSearchRepository(ElasticSearchClientFactory searchClientFactory,
                                                    ElasticSearchFrequentlyRelatedItemSearchProcessor builder); }
ElasticSearchRelatedItemSearchRepository implements RelatedItemSearchRepository<FrequentlyRelatedSearchResult[]> { @Override public SearchResultEventWithSearchRequestKey[] findRelatedItems(Configuration configuration, RelatedItemSearch[] searches) { log.debug("request to execute {} searches",searches.length); SearchResultEventWithSearchRequestKey[] results; MultiSearchResponse sr; long startNanos = System.nanoTime(); try { sr = frequentlyRelatedWithSearchBuilder.executeSearch(elasticClient,searches); log.debug("Processing results for search {} request(s)",searches.length); results = frequentlyRelatedWithSearchBuilder.processMultiSearchResponse(searches,sr); log.debug("Search Completed, returning processed results."); } catch(ElasticsearchTimeoutException timeoutException) { long time = (System.nanoTime()-startNanos)/1000000; log.warn("Timeout exception executing search request: ",timeoutException); 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()); } } catch(Exception searchException) { long time = (System.nanoTime()-startNanos)/1000000; log.warn("Exception executing search request: ",searchException); 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()); } } return results; } ElasticSearchRelatedItemSearchRepository(ElasticSearchClientFactory searchClientFactory,
                                                    ElasticSearchFrequentlyRelatedItemSearchProcessor builder); @Override SearchResultEventWithSearchRequestKey[] findRelatedItems(Configuration configuration,
                                                                    RelatedItemSearch[] searches); @Override void shutdown(); }
ElasticSearchRelatedItemSearchRepository implements RelatedItemSearchRepository<FrequentlyRelatedSearchResult[]> { @Override public SearchResultEventWithSearchRequestKey[] findRelatedItems(Configuration configuration, RelatedItemSearch[] searches) { log.debug("request to execute {} searches",searches.length); SearchResultEventWithSearchRequestKey[] results; MultiSearchResponse sr; long startNanos = System.nanoTime(); try { sr = frequentlyRelatedWithSearchBuilder.executeSearch(elasticClient,searches); log.debug("Processing results for search {} request(s)",searches.length); results = frequentlyRelatedWithSearchBuilder.processMultiSearchResponse(searches,sr); log.debug("Search Completed, returning processed results."); } catch(ElasticsearchTimeoutException timeoutException) { long time = (System.nanoTime()-startNanos)/1000000; log.warn("Timeout exception executing search request: ",timeoutException); 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()); } } catch(Exception searchException) { long time = (System.nanoTime()-startNanos)/1000000; log.warn("Exception executing search request: ",searchException); 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()); } } return results; } ElasticSearchRelatedItemSearchRepository(ElasticSearchClientFactory searchClientFactory,
                                                    ElasticSearchFrequentlyRelatedItemSearchProcessor builder); @Override SearchResultEventWithSearchRequestKey[] findRelatedItems(Configuration configuration,
                                                                    RelatedItemSearch[] searches); @Override void shutdown();  }