use of nl.knaw.huygens.timbuctoo.core.dto.QuickSearchResult in project timbuctoo by HuygensING.
the class TinkerPopOperationsTest method doQuickSearchLetsLimitTheAmountOfResults.
@Test
public void doQuickSearchLetsLimitTheAmountOfResults() {
Vres vres = createConfiguration();
GremlinEntityFetcher entityFetcher = new GremlinEntityFetcher();
UUID id1 = UUID.randomUUID();
UUID id2 = UUID.randomUUID();
UUID id3 = UUID.randomUUID();
TinkerPopGraphManager graphManager = newGraph().withVertex(v -> v.withTimId(id1).withType("thing").withVre("test").withProperty("rev", 1).withProperty("testthing_displayName", "matching").isLatest(true).withLabel("testthing")).withVertex(v -> v.withTimId(id2).withType("thing").withVre("test").withProperty("rev", 1).withProperty("testthing_displayName", "also matching").isLatest(true).withLabel("testthing")).withVertex(v -> v.withTimId(id3).withType("thing").withVre("test").withProperty("rev", 1).withProperty("testthing_displayName", "different name").isLatest(true).withLabel("testthing")).wrap();
IndexHandler indexHandler = mock(IndexHandler.class);
when(indexHandler.hasQuickSearchIndexFor(any(Collection.class))).thenReturn(true);
when(indexHandler.findByQuickSearch(any(Collection.class), any())).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("testthings").get();
QuickSearch quickSearch = QuickSearch.fromQueryString("matching");
List<QuickSearchResult> result = instance.doQuickSearch(collection, quickSearch, 1);
assertThat(result, hasSize(1));
}
use of nl.knaw.huygens.timbuctoo.core.dto.QuickSearchResult in project timbuctoo by HuygensING.
the class TinkerPopOperationsTest method doQuickSearchUsesTheIndexToSearchTheEntity.
@Test
public void doQuickSearchUsesTheIndexToSearchTheEntity() {
Vres vres = createConfiguration();
GremlinEntityFetcher entityFetcher = new GremlinEntityFetcher();
UUID id1 = UUID.randomUUID();
UUID id2 = UUID.randomUUID();
UUID id3 = UUID.randomUUID();
TinkerPopGraphManager graphManager = newGraph().withVertex(v -> v.withTimId(id1).withType("thing").withVre("test").withProperty("rev", 1).withProperty("testthing_displayName", "matching").isLatest(true).withLabel("testthing")).withVertex(v -> v.withTimId(id2).withType("thing").withVre("test").withProperty("rev", 1).withProperty("testthing_displayName", "also matching").isLatest(true).withLabel("testthing")).withVertex(v -> v.withTimId(id3).withType("thing").withVre("test").withProperty("rev", 1).withProperty("testthing_displayName", "different name").isLatest(true).withLabel("testthing")).wrap();
IndexHandler indexHandler = mock(IndexHandler.class);
when(indexHandler.hasQuickSearchIndexFor(any(Collection.class))).thenReturn(true);
when(indexHandler.findByQuickSearch(any(Collection.class), any())).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("testthings").get();
QuickSearch quickSearch = QuickSearch.fromQueryString("matching");
List<QuickSearchResult> result = instance.doQuickSearch(collection, quickSearch, 3);
assertThat(result.stream().map(e -> e.getId()).collect(toList()), containsInAnyOrder(id1, id2));
verify(indexHandler).findByQuickSearch(collection, quickSearch);
}
use of nl.knaw.huygens.timbuctoo.core.dto.QuickSearchResult in project timbuctoo by HuygensING.
the class TimbuctooActionsGetTest method doQuickSearchReturnsTheValueOfDataStoreOperations.
@Test
public void doQuickSearchReturnsTheValueOfDataStoreOperations() {
List<QuickSearchResult> entities = Lists.newArrayList();
QuickSearch query = QuickSearch.fromQueryString("");
Collection collection = collWithCollectionName("coll");
int limit = 1;
when(dataStoreOperations.doQuickSearch(collection, query, limit)).thenReturn(entities);
List<QuickSearchResult> searchResult = instance.doQuickSearch(collection, query, null, limit);
assertThat(searchResult, is(sameInstance(entities)));
}
use of nl.knaw.huygens.timbuctoo.core.dto.QuickSearchResult in project timbuctoo by HuygensING.
the class TimbuctooActionsGetTest method doQuickSearchCallsDoKeywordQuickSearchWhenTheCollectionIsAKeywordCollection.
@Test
public void doQuickSearchCallsDoKeywordQuickSearchWhenTheCollectionIsAKeywordCollection() {
List<QuickSearchResult> entities = Lists.newArrayList();
QuickSearch query = QuickSearch.fromQueryString("");
String keywordType = "";
Collection collection = keywordCollWithCollectionName("coll");
int limit = 1;
when(dataStoreOperations.doKeywordQuickSearch(collection, keywordType, query, limit)).thenReturn(entities);
List<QuickSearchResult> searchResult = instance.doQuickSearch(collection, query, keywordType, limit);
assertThat(searchResult, is(sameInstance(entities)));
}
use of nl.knaw.huygens.timbuctoo.core.dto.QuickSearchResult in project timbuctoo by HuygensING.
the class AutocompleteServiceTest method searchConvertsTheReadEntityToJson.
@Test
public void searchConvertsTheReadEntityToJson() 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(), isNull(), anyInt())).willReturn(Lists.newArrayList(entity));
AutocompleteService instance = new AutocompleteService((collection, id1, rev) -> URI.create("http://example.com/" + collection + "/" + id1 + "?rev=" + rev), timbuctooActions);
String query = "*author*";
JsonNode result = instance.search(collectionName, Optional.of(query), Optional.empty());
assertThat(result.toString(), sameJSONAs(jsnA(jsnO("value", jsn("[TEMP] An author"), "key", jsn("http://example.com/wwpersons/" + id.toString() + "?rev=2"))).toString()));
verify(timbuctooActions).doQuickSearch(argThat(hasProperty("collectionName", equalTo(collectionName))), any(QuickSearch.class), isNull(), intThat(is(50)));
}
Aggregations