use of nl.knaw.huygens.timbuctoo.core.dto.QuickSearch 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.QuickSearch 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.QuickSearch in project timbuctoo by HuygensING.
the class Neo4JIndexHandlerTest method findKeywordsByQuickSearchDoesNotFilterOnKeywordTypeWhenKeywordtypesIsNull.
@Test
public void findKeywordsByQuickSearchDoesNotFilterOnKeywordTypeWhenKeywordtypesIsNull() {
String id1 = UUID.randomUUID().toString();
String id2 = UUID.randomUUID().toString();
String id3 = UUID.randomUUID().toString();
TinkerPopGraphManager tinkerPopGraphManager = newGraph().withVertex(v -> v.withTimId(id1).withProperty("keyword_type", "keywordType").withProperty("displayName", "query")).withVertex(v -> v.withProperty("keyword_type", "otherType").withTimId(id2).withProperty("displayName", "query2")).withVertex(v -> v.withProperty("keyword_type", "otherType").withTimId(id3).withProperty("displayName", "notmatching")).wrap();
Neo4jIndexHandler instance = new Neo4jIndexHandler(tinkerPopGraphManager);
addToQuickSearchIndex(instance, collection, tinkerPopGraphManager.getGraph().traversal().V().has("tim_id", id1).next());
addToQuickSearchIndex(instance, collection, tinkerPopGraphManager.getGraph().traversal().V().has("tim_id", id2).next());
addToQuickSearchIndex(instance, collection, tinkerPopGraphManager.getGraph().traversal().V().has("tim_id", id3).next());
QuickSearch quickSearch = QuickSearch.fromQueryString("query");
GraphTraversal<Vertex, Vertex> vertices = instance.findKeywordsByQuickSearch(collection, quickSearch, null);
assertThat(vertices.map(v -> v.get().value("tim_id")).toList(), containsInAnyOrder(id1, id2));
}
use of nl.knaw.huygens.timbuctoo.core.dto.QuickSearch in project timbuctoo by HuygensING.
the class Neo4JIndexHandlerTest method findKeywordsByQuickSearchFiltersTheIndexResultsOnTheRightKeywordType.
@Test
public void findKeywordsByQuickSearchFiltersTheIndexResultsOnTheRightKeywordType() {
String id1 = UUID.randomUUID().toString();
String id2 = UUID.randomUUID().toString();
String id3 = UUID.randomUUID().toString();
TinkerPopGraphManager tinkerPopGraphManager = newGraph().withVertex(v -> v.withTimId(id1).withProperty("keyword_type", "keywordType").withProperty("displayName", "query")).withVertex(v -> v.withProperty("keyword_type", "otherType").withTimId(id2).withProperty("displayName", "query2")).withVertex(v -> v.withProperty("keyword_type", "otherType").withTimId(id3).withProperty("displayName", "notmatching")).wrap();
Neo4jIndexHandler instance = new Neo4jIndexHandler(tinkerPopGraphManager);
addToQuickSearchIndex(instance, collection, tinkerPopGraphManager.getGraph().traversal().V().has("tim_id", id1).next());
addToQuickSearchIndex(instance, collection, tinkerPopGraphManager.getGraph().traversal().V().has("tim_id", id2).next());
addToQuickSearchIndex(instance, collection, tinkerPopGraphManager.getGraph().traversal().V().has("tim_id", id3).next());
QuickSearch quickSearch = QuickSearch.fromQueryString("query");
GraphTraversal<Vertex, Vertex> vertices = instance.findKeywordsByQuickSearch(collection, quickSearch, "keywordType");
assertThat(vertices.map(v -> v.get().value("tim_id")).toList(), containsInAnyOrder(id1));
}
use of nl.knaw.huygens.timbuctoo.core.dto.QuickSearch in project timbuctoo by HuygensING.
the class Neo4JIndexHandlerTest method findByQuickSearchRetrievesTheVerticesFromTheIndexAndCreatesTraversalForThem.
@Test
public void findByQuickSearchRetrievesTheVerticesFromTheIndexAndCreatesTraversalForThem() {
String id1 = UUID.randomUUID().toString();
String id2 = UUID.randomUUID().toString();
String id3 = UUID.randomUUID().toString();
TinkerPopGraphManager tinkerPopGraphManager = newGraph().withVertex(v -> v.withTimId(id1).withProperty("displayName", "query")).withVertex(v -> v.withTimId(id2).withProperty("displayName", "query2")).withVertex(v -> v.withTimId(id3).withProperty("displayName", "notmatching")).wrap();
Neo4jIndexHandler instance = new Neo4jIndexHandler(tinkerPopGraphManager);
addToQuickSearchIndex(instance, collection, tinkerPopGraphManager.getGraph().traversal().V().has("tim_id", id1).next());
addToQuickSearchIndex(instance, collection, tinkerPopGraphManager.getGraph().traversal().V().has("tim_id", id2).next());
addToQuickSearchIndex(instance, collection, tinkerPopGraphManager.getGraph().traversal().V().has("tim_id", id3).next());
QuickSearch quickSearch = QuickSearch.fromQueryString("query*");
GraphTraversal<Vertex, Vertex> vertices = instance.findByQuickSearch(collection, quickSearch);
assertThat(vertices.map(v -> v.get().value("tim_id")).toList(), containsInAnyOrder(id1, id2));
}
Aggregations