use of nl.knaw.huygens.timbuctoo.core.dto.QuickSearchResult in project timbuctoo by HuygensING.
the class TinkerPopOperationsTest method doKeywordQuickSearchUsesAnIndexToRetrieveTheResults.
@Test
public void doKeywordQuickSearchUsesAnIndexToRetrieveTheResults() {
Vres vres = createConfiguration();
GremlinEntityFetcher entityFetcher = new GremlinEntityFetcher();
UUID id1 = UUID.randomUUID();
UUID id2 = UUID.randomUUID();
UUID id3 = UUID.randomUUID();
String keywordType = "keywordType";
TinkerPopGraphManager graphManager = newGraph().withVertex(v -> v.withTimId(id1).withType("keyword").withVre("test").withProperty("rev", 1).withProperty("testkeyword_displayName", "matching").isLatest(true).withProperty("keyword_type", keywordType).withLabel("testkeyword")).withVertex(v -> v.withTimId(id2).withType("keyword").withVre("test").withProperty("rev", 1).withProperty("testkeyword_displayName", "also matching").isLatest(true).withProperty("keyword_type", keywordType).withLabel("testkeyword")).withVertex(v -> v.withTimId(id3).withType("keyword").withVre("test").withProperty("rev", 1).withProperty("testkeyword_displayName", "different name").isLatest(true).withProperty("keyword_type", keywordType).withLabel("testkeyword")).wrap();
IndexHandler indexHandler = mock(IndexHandler.class);
when(indexHandler.hasQuickSearchIndexFor(any(Collection.class))).thenReturn(true);
when(indexHandler.findKeywordsByQuickSearch(any(Collection.class), any(), anyString())).thenReturn(graphManager.getGraph().traversal().V().has("tim_id", within(id1.toString(), id2.toString())));
TinkerPopOperations instance = new TinkerPopOperations(graphManager, mock(ChangeListener.class), entityFetcher, vres, indexHandler);
Collection collection = vres.getCollection("testkeywords").get();
QuickSearch quickSearch = QuickSearch.fromQueryString("matching");
List<QuickSearchResult> result = instance.doKeywordQuickSearch(collection, keywordType, quickSearch, 3);
assertThat(result.stream().map(e -> e.getId()).collect(toList()), contains(id1, id2));
verify(indexHandler).findKeywordsByQuickSearch(collection, quickSearch, keywordType);
}
use of nl.knaw.huygens.timbuctoo.core.dto.QuickSearchResult in project timbuctoo by HuygensING.
the class AutocompleteServiceTest method searchFiltersKeywordsByType.
@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://example.com/" + coll + "/" + id1 + "?rev=" + rev);
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://example.com/wwkeywords/" + id.toString() + "?rev=2"))).toString()));
verify(timbuctooActions).doQuickSearch(argThat(hasProperty("collectionName", equalTo(collectionName))), any(QuickSearch.class), argThat(is(keywordType)), intThat(is(50)));
}
use of nl.knaw.huygens.timbuctoo.core.dto.QuickSearchResult in project timbuctoo by HuygensING.
the class AutocompleteServiceTest method searchRequests1000ResultsWhenTheQueryIsEmpty.
@Test
public void searchRequests1000ResultsWhenTheQueryIsEmpty() throws Exception {
UUID id = UUID.randomUUID();
String collectionName = "wwpersons";
QuickSearchResult entity = QuickSearchResult.create("[TEMP] An author", id, 2);
TimbuctooActions timbuctooActions = mock(TimbuctooActions.class);
given(timbuctooActions.getCollectionMetadata(anyString())).willReturn(collWithCollectionName(collectionName));
given(timbuctooActions.doQuickSearch(any(), any(), anyString(), anyInt())).willReturn(Lists.newArrayList(entity));
AutocompleteService instance = new AutocompleteService((collection, id1, rev) -> URI.create("http://example.com/" + collection + "/" + id1 + "?rev=" + rev), timbuctooActions);
instance.search(collectionName, Optional.empty(), Optional.empty());
verify(timbuctooActions).doQuickSearch(any(Collection.class), any(QuickSearch.class), any(), intThat(is(1000)));
}
use of nl.knaw.huygens.timbuctoo.core.dto.QuickSearchResult in project timbuctoo by HuygensING.
the class AutocompleteService method search.
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()))));
}
use of nl.knaw.huygens.timbuctoo.core.dto.QuickSearchResult in project timbuctoo by HuygensING.
the class TinkerPopOperationsTest method doKeywordQuickSearchLetsLimitLimitTheAmountOfResults.
@Test
public void doKeywordQuickSearchLetsLimitLimitTheAmountOfResults() {
Vres vres = createConfiguration();
GremlinEntityFetcher entityFetcher = new GremlinEntityFetcher();
UUID id1 = UUID.randomUUID();
UUID id2 = UUID.randomUUID();
UUID id3 = UUID.randomUUID();
String keywordType = "keywordType";
TinkerPopGraphManager graphManager = newGraph().withVertex(v -> v.withTimId(id1).withType("keyword").withVre("test").withProperty("rev", 1).withProperty("testkeyword_displayName", "matching").isLatest(true).withProperty("keyword_type", keywordType).withLabel("testkeyword")).withVertex(v -> v.withTimId(id2).withType("keyword").withVre("test").withProperty("rev", 1).withProperty("testkeyword_displayName", "also matching").isLatest(true).withProperty("keyword_type", keywordType).withLabel("testkeyword")).withVertex(v -> v.withTimId(id3).withType("keyword").withVre("test").withProperty("rev", 1).withProperty("testkeyword_displayName", "different name").isLatest(true).withProperty("keyword_type", keywordType).withLabel("testkeyword")).wrap();
IndexHandler indexHandler = mock(IndexHandler.class);
when(indexHandler.hasQuickSearchIndexFor(any(Collection.class))).thenReturn(true);
when(indexHandler.findKeywordsByQuickSearch(any(Collection.class), any(), anyString())).thenReturn(graphManager.getGraph().traversal().V().has("tim_id", within(id1.toString(), id2.toString())));
TinkerPopOperations instance = new TinkerPopOperations(graphManager, mock(ChangeListener.class), entityFetcher, vres, indexHandler);
Collection collection = vres.getCollection("testkeywords").get();
QuickSearch quickSearch = QuickSearch.fromQueryString("matching");
List<QuickSearchResult> result = instance.doKeywordQuickSearch(collection, keywordType, quickSearch, 1);
assertThat(result, hasSize(1));
}
Aggregations