@Test public void searchFiltersKeywordsByType() throws InvalidCollectionException { String query = "*foo bar*"; String keywordType = "maritalStatus"; String collectionName = "wwkeywords"; UUID id = UUID.randomUUID(); QuickSearchResult readEntity = QuickSearchResult.create("a keyword", id, 2); TimbuctooActions timbuctooActions = mock(TimbuctooActions.class); given(timbuctooActions.getCollectionMetadata(anyString())) .willReturn(keywordCollWithCollectionName(collectionName)); given(timbuctooActions.doQuickSearch(any(), any(), anyString(), anyInt())) .willReturn(Lists.newArrayList(readEntity)); UrlGenerator urlGenerator = (coll, id1, rev) -> URI.create("http: AutocompleteService instance = new AutocompleteService( urlGenerator, timbuctooActions); JsonNode result = instance.search(collectionName, Optional.of(query), Optional.of(keywordType)); assertThat(result.toString(), sameJSONAs(jsnA( jsnO("value", jsn("a keyword"), "key", jsn("http: ).toString())); verify(timbuctooActions).doQuickSearch( argThat(hasProperty("collectionName", equalTo(collectionName))), any(QuickSearch.class), argThat(is(keywordType)), intThat(is(50)) ); }
public JsonNode search(String collectionName, Optional<String> query, Optional<String> keywordType) throws InvalidCollectionException { final Collection collection = timbuctooActions.getCollectionMetadata(collectionName); int limit = query.isPresent() ? 50 : 1000; String queryString = query.orElse(null); QuickSearch quickSearch = QuickSearch.fromQueryString(queryString); List<QuickSearchResult> results = timbuctooActions.doQuickSearch( collection, quickSearch, keywordType.orElse(null), limit ); return jsnA(results.stream().map(entity -> jsnO( "value", jsn(entity.getIndexedValue()), "key", jsn(autoCompleteUrlFor.apply(collectionName, entity.getId(), entity.getRev()).toString()) ))); }
AutocompleteService { public JsonNode search(String collectionName, Optional<String> query, Optional<String> keywordType) throws InvalidCollectionException { final Collection collection = timbuctooActions.getCollectionMetadata(collectionName); int limit = query.isPresent() ? 50 : 1000; String queryString = query.orElse(null); QuickSearch quickSearch = QuickSearch.fromQueryString(queryString); List<QuickSearchResult> results = timbuctooActions.doQuickSearch( collection, quickSearch, keywordType.orElse(null), limit ); return jsnA(results.stream().map(entity -> jsnO( "value", jsn(entity.getIndexedValue()), "key", jsn(autoCompleteUrlFor.apply(collectionName, entity.getId(), entity.getRev()).toString()) ))); } }
AutocompleteService { public JsonNode search(String collectionName, Optional<String> query, Optional<String> keywordType) throws InvalidCollectionException { final Collection collection = timbuctooActions.getCollectionMetadata(collectionName); int limit = query.isPresent() ? 50 : 1000; String queryString = query.orElse(null); QuickSearch quickSearch = QuickSearch.fromQueryString(queryString); List<QuickSearchResult> results = timbuctooActions.doQuickSearch( collection, quickSearch, keywordType.orElse(null), limit ); return jsnA(results.stream().map(entity -> jsnO( "value", jsn(entity.getIndexedValue()), "key", jsn(autoCompleteUrlFor.apply(collectionName, entity.getId(), entity.getRev()).toString()) ))); } AutocompleteService(UrlGenerator autoCompleteUrlFor, TimbuctooActions timbuctooActions); }
AutocompleteService { public JsonNode search(String collectionName, Optional<String> query, Optional<String> keywordType) throws InvalidCollectionException { final Collection collection = timbuctooActions.getCollectionMetadata(collectionName); int limit = query.isPresent() ? 50 : 1000; String queryString = query.orElse(null); QuickSearch quickSearch = QuickSearch.fromQueryString(queryString); List<QuickSearchResult> results = timbuctooActions.doQuickSearch( collection, quickSearch, keywordType.orElse(null), limit ); return jsnA(results.stream().map(entity -> jsnO( "value", jsn(entity.getIndexedValue()), "key", jsn(autoCompleteUrlFor.apply(collectionName, entity.getId(), entity.getRev()).toString()) ))); } AutocompleteService(UrlGenerator autoCompleteUrlFor, TimbuctooActions timbuctooActions); JsonNode search(String collectionName, Optional<String> query, Optional<String> keywordType); }
AutocompleteService { public JsonNode search(String collectionName, Optional<String> query, Optional<String> keywordType) throws InvalidCollectionException { final Collection collection = timbuctooActions.getCollectionMetadata(collectionName); int limit = query.isPresent() ? 50 : 1000; String queryString = query.orElse(null); QuickSearch quickSearch = QuickSearch.fromQueryString(queryString); List<QuickSearchResult> results = timbuctooActions.doQuickSearch( collection, quickSearch, keywordType.orElse(null), limit ); return jsnA(results.stream().map(entity -> jsnO( "value", jsn(entity.getIndexedValue()), "key", jsn(autoCompleteUrlFor.apply(collectionName, entity.getId(), entity.getRev()).toString()) ))); } AutocompleteService(UrlGenerator autoCompleteUrlFor, TimbuctooActions timbuctooActions); JsonNode search(String collectionName, Optional<String> query, Optional<String> keywordType);  }