Search in sources :

Example 56 with GraphTraversal

use of org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal in project sqlg by pietermartin.

the class TestEdgeHas method testEdgeHas.

@Test
public void testEdgeHas() {
    Vertex stephen = this.sqlgGraph.addVertex("name", "stephen");
    Vertex marko = this.sqlgGraph.addVertex("name", "marko");
    stephen.addEdge("knows", marko, "weight", 1.0d);
    stephen.addEdge("knows", marko, "weight", 2.0d);
    this.sqlgGraph.tx().commit();
    GraphTraversal knows = vertexTraversal(this.sqlgGraph, stephen).outE("knows");
    knows.has("weight", 1.0d);
    Assert.assertEquals(1L, knows.count().next());
    Assert.assertEquals(1, vertexTraversal(this.sqlgGraph, stephen).outE("knows").has("weight", 1.0d).count().next(), 0);
}
Also used : Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) GraphTraversal(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal) BaseTest(org.umlg.sqlg.test.BaseTest) Test(org.junit.Test)

Example 57 with GraphTraversal

use of org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal in project timbuctoo by HuygensING.

the class DerivedListFacetDescription method filter.

@Override
public void filter(GraphTraversal<Vertex, Vertex> graphTraversal, List<FacetValue> facets) {
    Optional<FacetValue> first = facets.stream().filter(facetValue -> Objects.equals(facetValue.getName(), facetName)).findFirst();
    if (!first.isPresent()) {
        return;
    }
    FacetValue facetValue = first.get();
    if (!(facetValue instanceof ListFacetValue)) {
        return;
    }
    List<String> values = ((ListFacetValue) facetValue).getValues();
    if (values.isEmpty()) {
        return;
    }
    graphTraversal.where(__.bothE(relations).otherV().bothE(relationNames).otherV().values(propertyName).map(value -> parser.parse((String) value.get())).is(within(values)));
}
Also used : Objects(java.util.Objects) PropertyParser(nl.knaw.huygens.timbuctoo.search.description.PropertyParser) FacetValue(nl.knaw.huygens.timbuctoo.search.FacetValue) List(java.util.List) ListFacetGetter(nl.knaw.huygens.timbuctoo.search.description.facet.helpers.ListFacetGetter) Optional(java.util.Optional) org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__) P.within(org.apache.tinkerpop.gremlin.process.traversal.P.within) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) DerivedPropertyValueGetter(nl.knaw.huygens.timbuctoo.search.description.facet.helpers.DerivedPropertyValueGetter) GraphTraversal(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal) ListFacetValue(nl.knaw.huygens.timbuctoo.server.mediatypes.v2.search.ListFacetValue) FacetValue(nl.knaw.huygens.timbuctoo.search.FacetValue) ListFacetValue(nl.knaw.huygens.timbuctoo.server.mediatypes.v2.search.ListFacetValue) ListFacetValue(nl.knaw.huygens.timbuctoo.server.mediatypes.v2.search.ListFacetValue)

Example 58 with GraphTraversal

use of org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal 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));
}
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 59 with GraphTraversal

use of org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal 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));
}
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 60 with GraphTraversal

use of org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal in project timbuctoo by HuygensING.

the class Neo4JIndexHandlerTest method removeFromQuickSearchIndexRemovesTheVertexFromTheIndex.

@Test
public void removeFromQuickSearchIndexRemovesTheVertexFromTheIndex() {
    String id1 = UUID.randomUUID().toString();
    TinkerPopGraphManager tinkerPopGraphManager = newGraph().withVertex(v -> v.withTimId(id1)).wrap();
    Neo4jIndexHandler instance = new Neo4jIndexHandler(tinkerPopGraphManager);
    Vertex vertex = tinkerPopGraphManager.getGraph().traversal().V().has("tim_id", id1).next();
    instance.upsertIntoQuickSearchIndex(collection, "query", vertex, null);
    GraphTraversal<Vertex, Vertex> beforeRemoval = instance.findByQuickSearch(collection, QuickSearch.fromQueryString("query"));
    assertThat(beforeRemoval.hasNext(), is(true));
    instance.removeFromQuickSearchIndex(collection, vertex);
    GraphTraversal<Vertex, Vertex> afterRemoval = instance.findByQuickSearch(collection, QuickSearch.fromQueryString("query"));
    assertThat(afterRemoval.hasNext(), is(false));
}
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) Test(org.junit.Test)

Aggregations

GraphTraversal (org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal)93 Vertex (org.apache.tinkerpop.gremlin.structure.Vertex)67 Test (org.junit.Test)57 List (java.util.List)51 TestGraphBuilder.newGraph (nl.knaw.huygens.timbuctoo.util.TestGraphBuilder.newGraph)50 VertexMatcher.likeVertex (nl.knaw.huygens.timbuctoo.util.VertexMatcher.likeVertex)44 Before (org.junit.Before)42 Matchers.containsInAnyOrder (org.hamcrest.Matchers.containsInAnyOrder)40 Matchers.contains (org.hamcrest.Matchers.contains)39 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)35 Lists (com.google.common.collect.Lists)34 FacetValue (nl.knaw.huygens.timbuctoo.search.FacetValue)31 Optional (java.util.Optional)24 P (org.apache.tinkerpop.gremlin.process.traversal.P)21 org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__ (org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__)20 ListFacetValue (nl.knaw.huygens.timbuctoo.server.mediatypes.v2.search.ListFacetValue)19 Matchers.is (org.hamcrest.Matchers.is)17 Mockito.mock (org.mockito.Mockito.mock)17 Matchers.empty (org.hamcrest.Matchers.empty)15 Edge (org.apache.tinkerpop.gremlin.structure.Edge)14