Search in sources :

Example 1 with QuickSearch

use of nl.knaw.huygens.timbuctoo.core.dto.QuickSearch 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);
}
Also used : ImmutableCreateProperty(nl.knaw.huygens.timbuctoo.core.dto.rdf.ImmutableCreateProperty) AlreadyUpdatedException(nl.knaw.huygens.timbuctoo.core.AlreadyUpdatedException) NodeFactory(org.apache.jena.graph.NodeFactory) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) CreateCollection(nl.knaw.huygens.timbuctoo.core.dto.CreateCollection) Matchers.not(org.hamcrest.Matchers.not) CreateEntityStubs.withProperties(nl.knaw.huygens.timbuctoo.core.dto.CreateEntityStubs.withProperties) Try(javaslang.control.Try) QuickSearch(nl.knaw.huygens.timbuctoo.core.dto.QuickSearch) RdfProperty(nl.knaw.huygens.timbuctoo.core.dto.rdf.RdfProperty) Matchers.nullValue(org.hamcrest.Matchers.nullValue) TestGraphBuilder.newGraph(nl.knaw.huygens.timbuctoo.util.TestGraphBuilder.newGraph) HAS_ENTITY_NODE_RELATION_NAME(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection.HAS_ENTITY_NODE_RELATION_NAME) QuickSearchResult(nl.knaw.huygens.timbuctoo.core.dto.QuickSearchResult) Matchers.allOf(org.hamcrest.Matchers.allOf) TinkerPopGraphManager(nl.knaw.huygens.timbuctoo.server.TinkerPopGraphManager) COLLECTION_NAME_PROPERTY_NAME(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection.COLLECTION_NAME_PROPERTY_NAME) ValueTypeInUse(nl.knaw.huygens.timbuctoo.core.dto.rdf.ValueTypeInUse) ChangeListener(nl.knaw.huygens.timbuctoo.database.tinkerpop.changelistener.ChangeListener) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) ReadEntity(nl.knaw.huygens.timbuctoo.core.dto.ReadEntity) Element(org.apache.tinkerpop.gremlin.structure.Element) Matchers.contains(org.hamcrest.Matchers.contains) Vre(nl.knaw.huygens.timbuctoo.model.vre.Vre) Matchers.is(org.hamcrest.Matchers.is) TinkerPopOperationsStubs.forGraphWrapperAndMappings(nl.knaw.huygens.timbuctoo.database.tinkerpop.TinkerPopOperationsStubs.forGraphWrapperAndMappings) CreateEntity(nl.knaw.huygens.timbuctoo.core.dto.CreateEntity) Matchers.containsString(org.hamcrest.Matchers.containsString) Mockito.mock(org.mockito.Mockito.mock) LabelP(org.apache.tinkerpop.gremlin.neo4j.process.traversal.LabelP) RAW_PROPERTY_EDGE_NAME(nl.knaw.huygens.timbuctoo.database.tinkerpop.TinkerpopSaver.RAW_PROPERTY_EDGE_NAME) Matchers.anyString(org.mockito.Matchers.anyString) ArrayList(java.util.ArrayList) Matchers.hasProperty(org.hamcrest.Matchers.hasProperty) CreateRelation(nl.knaw.huygens.timbuctoo.core.dto.CreateRelation) Lists(com.google.common.collect.Lists) TinkerPopOperationsStubs.forGraphMappingsAndChangeListener(nl.knaw.huygens.timbuctoo.database.tinkerpop.TinkerPopOperationsStubs.forGraphMappingsAndChangeListener) HAS_ENTITY_RELATION_NAME(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection.HAS_ENTITY_RELATION_NAME) TinkerPopOperationsStubs.forGraphWrapper(nl.knaw.huygens.timbuctoo.database.tinkerpop.TinkerPopOperationsStubs.forGraphWrapper) Matchers.hasSize(org.hamcrest.Matchers.hasSize) OptionalPresentMatcher.present(nl.knaw.huygens.hamcrest.OptionalPresentMatcher.present) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) RelationType(nl.knaw.huygens.timbuctoo.core.dto.RelationType) DataStream(nl.knaw.huygens.timbuctoo.core.dto.DataStream) Test(org.junit.Test) IOException(java.io.IOException) T(org.apache.tinkerpop.gremlin.structure.T) Direction(org.apache.tinkerpop.gremlin.structure.Direction) Database(nl.knaw.huygens.timbuctoo.rdf.Database) HAS_DISPLAY_NAME_RELATION_NAME(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection.HAS_DISPLAY_NAME_RELATION_NAME) Matchers.sameInstance(org.hamcrest.Matchers.sameInstance) RDF_URI_PROP(nl.knaw.huygens.timbuctoo.rdf.Database.RDF_URI_PROP) GraphReadUtils.getProp(nl.knaw.huygens.timbuctoo.model.GraphReadUtils.getProp) Change(nl.knaw.huygens.timbuctoo.model.Change) P.within(org.apache.tinkerpop.gremlin.process.traversal.P.within) SameJSONAs.sameJSONAs(uk.co.datumedge.hamcrest.json.SameJSONAs.sameJSONAs) StreamIterator.stream(nl.knaw.huygens.timbuctoo.util.StreamIterator.stream) PropertyTypes.localProperty(nl.knaw.huygens.timbuctoo.model.properties.PropertyTypes.localProperty) Graph(org.apache.tinkerpop.gremlin.structure.Graph) RDF_SYNONYM_PROP(nl.knaw.huygens.timbuctoo.rdf.Database.RDF_SYNONYM_PROP) StringProperty(nl.knaw.huygens.timbuctoo.core.dto.property.StringProperty) VertexMatcher.likeVertex(nl.knaw.huygens.timbuctoo.util.VertexMatcher.likeVertex) MockitoHamcrest.argThat(org.mockito.hamcrest.MockitoHamcrest.argThat) RelationNotPossibleException(nl.knaw.huygens.timbuctoo.core.RelationNotPossibleException) URI(java.net.URI) IS_RELATION_COLLECTION_PROPERTY_NAME(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection.IS_RELATION_COLLECTION_PROPERTY_NAME) org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.has(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.has) CollectionBuilder(nl.knaw.huygens.timbuctoo.core.dto.dataset.CollectionBuilder) EntityFinisherHelper(nl.knaw.huygens.timbuctoo.core.EntityFinisherHelper) NotFoundException(nl.knaw.huygens.timbuctoo.core.NotFoundException) UUID(java.util.UUID) Instant(java.time.Instant) RAW_COLLECTION_NAME_PROPERTY_NAME(nl.knaw.huygens.timbuctoo.database.tinkerpop.TinkerpopSaver.RAW_COLLECTION_NAME_PROPERTY_NAME) UpdateEntity(nl.knaw.huygens.timbuctoo.core.dto.UpdateEntity) List(java.util.List) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) Matchers.equalTo(org.hamcrest.Matchers.equalTo) Optional(java.util.Optional) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) JsonBuilder.jsnO(nl.knaw.huygens.timbuctoo.util.JsonBuilder.jsnO) Collection(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection) TinkerPopOperationsStubs.forGraphMappingsAndIndex(nl.knaw.huygens.timbuctoo.database.tinkerpop.TinkerPopOperationsStubs.forGraphMappingsAndIndex) VERSION_OF(nl.knaw.huygens.timbuctoo.database.tinkerpop.VertexDuplicator.VERSION_OF) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) VreStubs.minimalCorrectVre(nl.knaw.huygens.timbuctoo.model.vre.VreStubs.minimalCorrectVre) CollectionNameHelper.defaultEntityTypeName(nl.knaw.huygens.timbuctoo.core.CollectionNameHelper.defaultEntityTypeName) VresBuilder(nl.knaw.huygens.timbuctoo.model.vre.vres.VresBuilder) JsonBuilder.jsn(nl.knaw.huygens.timbuctoo.util.JsonBuilder.jsn) Edge(org.apache.tinkerpop.gremlin.structure.Edge) RdfReadProperty(nl.knaw.huygens.timbuctoo.core.dto.rdf.RdfReadProperty) Matchers.empty(org.hamcrest.Matchers.empty) PredicateInUse(nl.knaw.huygens.timbuctoo.core.dto.rdf.PredicateInUse) TimProperty(nl.knaw.huygens.timbuctoo.core.dto.property.TimProperty) RAW_ITEM_EDGE_NAME(nl.knaw.huygens.timbuctoo.database.tinkerpop.TinkerpopSaver.RAW_ITEM_EDGE_NAME) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ENTITY_TYPE_NAME_PROPERTY_NAME(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection.ENTITY_TYPE_NAME_PROPERTY_NAME) Mockito.when(org.mockito.Mockito.when) PropertyNameHelper.createPropName(nl.knaw.huygens.timbuctoo.database.tinkerpop.PropertyNameHelper.createPropName) Vres(nl.knaw.huygens.timbuctoo.model.vre.Vres) Entity(nl.knaw.huygens.timbuctoo.rdf.Entity) Mockito.verify(org.mockito.Mockito.verify) Collectors.toList(java.util.stream.Collectors.toList) Matchers.emptyIterable(org.hamcrest.Matchers.emptyIterable) EdgeMatcher.likeEdge(nl.knaw.huygens.timbuctoo.util.EdgeMatcher.likeEdge) HAS_COLLECTION_RELATION_NAME(nl.knaw.huygens.timbuctoo.model.vre.Vre.HAS_COLLECTION_RELATION_NAME) TinkerPopOperationsStubs.forGraphMappingsListenerAndIndex(nl.knaw.huygens.timbuctoo.database.tinkerpop.TinkerPopOperationsStubs.forGraphMappingsListenerAndIndex) HAS_PROPERTY_RELATION_NAME(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection.HAS_PROPERTY_RELATION_NAME) RAW_COLLECTION_EDGE_NAME(nl.knaw.huygens.timbuctoo.database.tinkerpop.TinkerpopSaver.RAW_COLLECTION_EDGE_NAME) UpdateRelation(nl.knaw.huygens.timbuctoo.core.dto.UpdateRelation) Vres(nl.knaw.huygens.timbuctoo.model.vre.Vres) Matchers.containsString(org.hamcrest.Matchers.containsString) Matchers.anyString(org.mockito.Matchers.anyString) QuickSearchResult(nl.knaw.huygens.timbuctoo.core.dto.QuickSearchResult) TinkerPopGraphManager(nl.knaw.huygens.timbuctoo.server.TinkerPopGraphManager) QuickSearch(nl.knaw.huygens.timbuctoo.core.dto.QuickSearch) CreateCollection(nl.knaw.huygens.timbuctoo.core.dto.CreateCollection) Collection(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection) ChangeListener(nl.knaw.huygens.timbuctoo.database.tinkerpop.changelistener.ChangeListener) TinkerPopOperationsStubs.forGraphMappingsAndChangeListener(nl.knaw.huygens.timbuctoo.database.tinkerpop.TinkerPopOperationsStubs.forGraphMappingsAndChangeListener) UUID(java.util.UUID) Test(org.junit.Test)

Example 2 with QuickSearch

use of nl.knaw.huygens.timbuctoo.core.dto.QuickSearch in project timbuctoo by HuygensING.

the class Neo4JIndexHandlerTest method findByQuickSearchReturnsAnEmtptyTraversalWhenNoVerticesAreFound.

@Test
public void findByQuickSearchReturnsAnEmtptyTraversalWhenNoVerticesAreFound() {
    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", "other")).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("queryWithoutResult");
    GraphTraversal<Vertex, Vertex> vertices = instance.findByQuickSearch(collection, quickSearch);
    assertThat(vertices.map(v -> v.get().value("tim_id")).toList(), is(empty()));
}
Also used : Matchers.empty(org.hamcrest.Matchers.empty) TinkerPopGraphManager(nl.knaw.huygens.timbuctoo.server.TinkerPopGraphManager) Matchers.not(org.hamcrest.Matchers.not) Test(org.junit.Test) Collection(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) UUID(java.util.UUID) Mockito.when(org.mockito.Mockito.when) GraphTraversal(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal) Assert.assertThat(org.junit.Assert.assertThat) QuickSearch(nl.knaw.huygens.timbuctoo.core.dto.QuickSearch) EdgeMatcher.likeEdge(nl.knaw.huygens.timbuctoo.util.EdgeMatcher.likeEdge) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) VertexMatcher.likeVertex(nl.knaw.huygens.timbuctoo.util.VertexMatcher.likeVertex) Optional(java.util.Optional) OptionalPresentMatcher.present(nl.knaw.huygens.hamcrest.OptionalPresentMatcher.present) Matchers.is(org.hamcrest.Matchers.is) Transaction(org.neo4j.graphdb.Transaction) TestGraphBuilder.newGraph(nl.knaw.huygens.timbuctoo.util.TestGraphBuilder.newGraph) Edge(org.apache.tinkerpop.gremlin.structure.Edge) Before(org.junit.Before) Mockito.mock(org.mockito.Mockito.mock) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) VertexMatcher.likeVertex(nl.knaw.huygens.timbuctoo.util.VertexMatcher.likeVertex) TinkerPopGraphManager(nl.knaw.huygens.timbuctoo.server.TinkerPopGraphManager) QuickSearch(nl.knaw.huygens.timbuctoo.core.dto.QuickSearch) Test(org.junit.Test)

Example 3 with QuickSearch

use of nl.knaw.huygens.timbuctoo.core.dto.QuickSearch in project timbuctoo by HuygensING.

the class Neo4JIndexHandlerTest method findByQuickSearchIsCaseInsensitive.

@Test
public void findByQuickSearchIsCaseInsensitive() {
    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));
}
Also used : Matchers.empty(org.hamcrest.Matchers.empty) TinkerPopGraphManager(nl.knaw.huygens.timbuctoo.server.TinkerPopGraphManager) Matchers.not(org.hamcrest.Matchers.not) Test(org.junit.Test) Collection(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) UUID(java.util.UUID) Mockito.when(org.mockito.Mockito.when) GraphTraversal(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal) Assert.assertThat(org.junit.Assert.assertThat) QuickSearch(nl.knaw.huygens.timbuctoo.core.dto.QuickSearch) EdgeMatcher.likeEdge(nl.knaw.huygens.timbuctoo.util.EdgeMatcher.likeEdge) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) VertexMatcher.likeVertex(nl.knaw.huygens.timbuctoo.util.VertexMatcher.likeVertex) Optional(java.util.Optional) OptionalPresentMatcher.present(nl.knaw.huygens.hamcrest.OptionalPresentMatcher.present) Matchers.is(org.hamcrest.Matchers.is) Transaction(org.neo4j.graphdb.Transaction) TestGraphBuilder.newGraph(nl.knaw.huygens.timbuctoo.util.TestGraphBuilder.newGraph) Edge(org.apache.tinkerpop.gremlin.structure.Edge) Before(org.junit.Before) Mockito.mock(org.mockito.Mockito.mock) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) VertexMatcher.likeVertex(nl.knaw.huygens.timbuctoo.util.VertexMatcher.likeVertex) TinkerPopGraphManager(nl.knaw.huygens.timbuctoo.server.TinkerPopGraphManager) QuickSearch(nl.knaw.huygens.timbuctoo.core.dto.QuickSearch) Test(org.junit.Test)

Example 4 with QuickSearch

use of nl.knaw.huygens.timbuctoo.core.dto.QuickSearch 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()))));
}
Also used : JsonBuilder.jsnO(nl.knaw.huygens.timbuctoo.util.JsonBuilder.jsnO) QuickSearchResult(nl.knaw.huygens.timbuctoo.core.dto.QuickSearchResult) UrlGenerator(nl.knaw.huygens.timbuctoo.crud.UrlGenerator) Collection(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection) ReadEntity(nl.knaw.huygens.timbuctoo.core.dto.ReadEntity) List(java.util.List) QuickSearch(nl.knaw.huygens.timbuctoo.core.dto.QuickSearch) InvalidCollectionException(nl.knaw.huygens.timbuctoo.crud.InvalidCollectionException) JsonBuilder.jsnA(nl.knaw.huygens.timbuctoo.util.JsonBuilder.jsnA) TimbuctooActions(nl.knaw.huygens.timbuctoo.core.TimbuctooActions) Optional(java.util.Optional) JsonNode(com.fasterxml.jackson.databind.JsonNode) JsonBuilder.jsn(nl.knaw.huygens.timbuctoo.util.JsonBuilder.jsn) QuickSearchResult(nl.knaw.huygens.timbuctoo.core.dto.QuickSearchResult) QuickSearch(nl.knaw.huygens.timbuctoo.core.dto.QuickSearch) Collection(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection)

Example 5 with QuickSearch

use of nl.knaw.huygens.timbuctoo.core.dto.QuickSearch 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));
}
Also used : ImmutableCreateProperty(nl.knaw.huygens.timbuctoo.core.dto.rdf.ImmutableCreateProperty) AlreadyUpdatedException(nl.knaw.huygens.timbuctoo.core.AlreadyUpdatedException) NodeFactory(org.apache.jena.graph.NodeFactory) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) CreateCollection(nl.knaw.huygens.timbuctoo.core.dto.CreateCollection) Matchers.not(org.hamcrest.Matchers.not) CreateEntityStubs.withProperties(nl.knaw.huygens.timbuctoo.core.dto.CreateEntityStubs.withProperties) Try(javaslang.control.Try) QuickSearch(nl.knaw.huygens.timbuctoo.core.dto.QuickSearch) RdfProperty(nl.knaw.huygens.timbuctoo.core.dto.rdf.RdfProperty) Matchers.nullValue(org.hamcrest.Matchers.nullValue) TestGraphBuilder.newGraph(nl.knaw.huygens.timbuctoo.util.TestGraphBuilder.newGraph) HAS_ENTITY_NODE_RELATION_NAME(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection.HAS_ENTITY_NODE_RELATION_NAME) QuickSearchResult(nl.knaw.huygens.timbuctoo.core.dto.QuickSearchResult) Matchers.allOf(org.hamcrest.Matchers.allOf) TinkerPopGraphManager(nl.knaw.huygens.timbuctoo.server.TinkerPopGraphManager) COLLECTION_NAME_PROPERTY_NAME(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection.COLLECTION_NAME_PROPERTY_NAME) ValueTypeInUse(nl.knaw.huygens.timbuctoo.core.dto.rdf.ValueTypeInUse) ChangeListener(nl.knaw.huygens.timbuctoo.database.tinkerpop.changelistener.ChangeListener) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) ReadEntity(nl.knaw.huygens.timbuctoo.core.dto.ReadEntity) Element(org.apache.tinkerpop.gremlin.structure.Element) Matchers.contains(org.hamcrest.Matchers.contains) Vre(nl.knaw.huygens.timbuctoo.model.vre.Vre) Matchers.is(org.hamcrest.Matchers.is) TinkerPopOperationsStubs.forGraphWrapperAndMappings(nl.knaw.huygens.timbuctoo.database.tinkerpop.TinkerPopOperationsStubs.forGraphWrapperAndMappings) CreateEntity(nl.knaw.huygens.timbuctoo.core.dto.CreateEntity) Matchers.containsString(org.hamcrest.Matchers.containsString) Mockito.mock(org.mockito.Mockito.mock) LabelP(org.apache.tinkerpop.gremlin.neo4j.process.traversal.LabelP) RAW_PROPERTY_EDGE_NAME(nl.knaw.huygens.timbuctoo.database.tinkerpop.TinkerpopSaver.RAW_PROPERTY_EDGE_NAME) Matchers.anyString(org.mockito.Matchers.anyString) ArrayList(java.util.ArrayList) Matchers.hasProperty(org.hamcrest.Matchers.hasProperty) CreateRelation(nl.knaw.huygens.timbuctoo.core.dto.CreateRelation) Lists(com.google.common.collect.Lists) TinkerPopOperationsStubs.forGraphMappingsAndChangeListener(nl.knaw.huygens.timbuctoo.database.tinkerpop.TinkerPopOperationsStubs.forGraphMappingsAndChangeListener) HAS_ENTITY_RELATION_NAME(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection.HAS_ENTITY_RELATION_NAME) TinkerPopOperationsStubs.forGraphWrapper(nl.knaw.huygens.timbuctoo.database.tinkerpop.TinkerPopOperationsStubs.forGraphWrapper) Matchers.hasSize(org.hamcrest.Matchers.hasSize) OptionalPresentMatcher.present(nl.knaw.huygens.hamcrest.OptionalPresentMatcher.present) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) RelationType(nl.knaw.huygens.timbuctoo.core.dto.RelationType) DataStream(nl.knaw.huygens.timbuctoo.core.dto.DataStream) Test(org.junit.Test) IOException(java.io.IOException) T(org.apache.tinkerpop.gremlin.structure.T) Direction(org.apache.tinkerpop.gremlin.structure.Direction) Database(nl.knaw.huygens.timbuctoo.rdf.Database) HAS_DISPLAY_NAME_RELATION_NAME(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection.HAS_DISPLAY_NAME_RELATION_NAME) Matchers.sameInstance(org.hamcrest.Matchers.sameInstance) RDF_URI_PROP(nl.knaw.huygens.timbuctoo.rdf.Database.RDF_URI_PROP) GraphReadUtils.getProp(nl.knaw.huygens.timbuctoo.model.GraphReadUtils.getProp) Change(nl.knaw.huygens.timbuctoo.model.Change) P.within(org.apache.tinkerpop.gremlin.process.traversal.P.within) SameJSONAs.sameJSONAs(uk.co.datumedge.hamcrest.json.SameJSONAs.sameJSONAs) StreamIterator.stream(nl.knaw.huygens.timbuctoo.util.StreamIterator.stream) PropertyTypes.localProperty(nl.knaw.huygens.timbuctoo.model.properties.PropertyTypes.localProperty) Graph(org.apache.tinkerpop.gremlin.structure.Graph) RDF_SYNONYM_PROP(nl.knaw.huygens.timbuctoo.rdf.Database.RDF_SYNONYM_PROP) StringProperty(nl.knaw.huygens.timbuctoo.core.dto.property.StringProperty) VertexMatcher.likeVertex(nl.knaw.huygens.timbuctoo.util.VertexMatcher.likeVertex) MockitoHamcrest.argThat(org.mockito.hamcrest.MockitoHamcrest.argThat) RelationNotPossibleException(nl.knaw.huygens.timbuctoo.core.RelationNotPossibleException) URI(java.net.URI) IS_RELATION_COLLECTION_PROPERTY_NAME(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection.IS_RELATION_COLLECTION_PROPERTY_NAME) org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.has(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.has) CollectionBuilder(nl.knaw.huygens.timbuctoo.core.dto.dataset.CollectionBuilder) EntityFinisherHelper(nl.knaw.huygens.timbuctoo.core.EntityFinisherHelper) NotFoundException(nl.knaw.huygens.timbuctoo.core.NotFoundException) UUID(java.util.UUID) Instant(java.time.Instant) RAW_COLLECTION_NAME_PROPERTY_NAME(nl.knaw.huygens.timbuctoo.database.tinkerpop.TinkerpopSaver.RAW_COLLECTION_NAME_PROPERTY_NAME) UpdateEntity(nl.knaw.huygens.timbuctoo.core.dto.UpdateEntity) List(java.util.List) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) Matchers.equalTo(org.hamcrest.Matchers.equalTo) Optional(java.util.Optional) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) JsonBuilder.jsnO(nl.knaw.huygens.timbuctoo.util.JsonBuilder.jsnO) Collection(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection) TinkerPopOperationsStubs.forGraphMappingsAndIndex(nl.knaw.huygens.timbuctoo.database.tinkerpop.TinkerPopOperationsStubs.forGraphMappingsAndIndex) VERSION_OF(nl.knaw.huygens.timbuctoo.database.tinkerpop.VertexDuplicator.VERSION_OF) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) VreStubs.minimalCorrectVre(nl.knaw.huygens.timbuctoo.model.vre.VreStubs.minimalCorrectVre) CollectionNameHelper.defaultEntityTypeName(nl.knaw.huygens.timbuctoo.core.CollectionNameHelper.defaultEntityTypeName) VresBuilder(nl.knaw.huygens.timbuctoo.model.vre.vres.VresBuilder) JsonBuilder.jsn(nl.knaw.huygens.timbuctoo.util.JsonBuilder.jsn) Edge(org.apache.tinkerpop.gremlin.structure.Edge) RdfReadProperty(nl.knaw.huygens.timbuctoo.core.dto.rdf.RdfReadProperty) Matchers.empty(org.hamcrest.Matchers.empty) PredicateInUse(nl.knaw.huygens.timbuctoo.core.dto.rdf.PredicateInUse) TimProperty(nl.knaw.huygens.timbuctoo.core.dto.property.TimProperty) RAW_ITEM_EDGE_NAME(nl.knaw.huygens.timbuctoo.database.tinkerpop.TinkerpopSaver.RAW_ITEM_EDGE_NAME) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ENTITY_TYPE_NAME_PROPERTY_NAME(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection.ENTITY_TYPE_NAME_PROPERTY_NAME) Mockito.when(org.mockito.Mockito.when) PropertyNameHelper.createPropName(nl.knaw.huygens.timbuctoo.database.tinkerpop.PropertyNameHelper.createPropName) Vres(nl.knaw.huygens.timbuctoo.model.vre.Vres) Entity(nl.knaw.huygens.timbuctoo.rdf.Entity) Mockito.verify(org.mockito.Mockito.verify) Collectors.toList(java.util.stream.Collectors.toList) Matchers.emptyIterable(org.hamcrest.Matchers.emptyIterable) EdgeMatcher.likeEdge(nl.knaw.huygens.timbuctoo.util.EdgeMatcher.likeEdge) HAS_COLLECTION_RELATION_NAME(nl.knaw.huygens.timbuctoo.model.vre.Vre.HAS_COLLECTION_RELATION_NAME) TinkerPopOperationsStubs.forGraphMappingsListenerAndIndex(nl.knaw.huygens.timbuctoo.database.tinkerpop.TinkerPopOperationsStubs.forGraphMappingsListenerAndIndex) HAS_PROPERTY_RELATION_NAME(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection.HAS_PROPERTY_RELATION_NAME) RAW_COLLECTION_EDGE_NAME(nl.knaw.huygens.timbuctoo.database.tinkerpop.TinkerpopSaver.RAW_COLLECTION_EDGE_NAME) UpdateRelation(nl.knaw.huygens.timbuctoo.core.dto.UpdateRelation) Vres(nl.knaw.huygens.timbuctoo.model.vre.Vres) Matchers.containsString(org.hamcrest.Matchers.containsString) Matchers.anyString(org.mockito.Matchers.anyString) QuickSearchResult(nl.knaw.huygens.timbuctoo.core.dto.QuickSearchResult) TinkerPopGraphManager(nl.knaw.huygens.timbuctoo.server.TinkerPopGraphManager) QuickSearch(nl.knaw.huygens.timbuctoo.core.dto.QuickSearch) CreateCollection(nl.knaw.huygens.timbuctoo.core.dto.CreateCollection) Collection(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection) ChangeListener(nl.knaw.huygens.timbuctoo.database.tinkerpop.changelistener.ChangeListener) TinkerPopOperationsStubs.forGraphMappingsAndChangeListener(nl.knaw.huygens.timbuctoo.database.tinkerpop.TinkerPopOperationsStubs.forGraphMappingsAndChangeListener) UUID(java.util.UUID) Test(org.junit.Test)

Aggregations

QuickSearch (nl.knaw.huygens.timbuctoo.core.dto.QuickSearch)12 Collection (nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection)12 Test (org.junit.Test)11 Optional (java.util.Optional)10 UUID (java.util.UUID)9 OptionalPresentMatcher.present (nl.knaw.huygens.hamcrest.OptionalPresentMatcher.present)9 TinkerPopGraphManager (nl.knaw.huygens.timbuctoo.server.TinkerPopGraphManager)9 EdgeMatcher.likeEdge (nl.knaw.huygens.timbuctoo.util.EdgeMatcher.likeEdge)9 TestGraphBuilder.newGraph (nl.knaw.huygens.timbuctoo.util.TestGraphBuilder.newGraph)9 VertexMatcher.likeVertex (nl.knaw.huygens.timbuctoo.util.VertexMatcher.likeVertex)9 Edge (org.apache.tinkerpop.gremlin.structure.Edge)9 Vertex (org.apache.tinkerpop.gremlin.structure.Vertex)9 Matchers.containsInAnyOrder (org.hamcrest.Matchers.containsInAnyOrder)9 Matchers.empty (org.hamcrest.Matchers.empty)9 Matchers.is (org.hamcrest.Matchers.is)9 Matchers.not (org.hamcrest.Matchers.not)9 Mockito.mock (org.mockito.Mockito.mock)9 Mockito.when (org.mockito.Mockito.when)9 QuickSearchResult (nl.knaw.huygens.timbuctoo.core.dto.QuickSearchResult)7 List (java.util.List)5