Search in sources :

Example 1 with Edge

use of org.vertexium.Edge in project vertexium by visallo.

the class Elasticsearch5SearchIndex method buildJsonContentFromExtendedDataMutations.

private XContentBuilder buildJsonContentFromExtendedDataMutations(Graph graph, Element element, String tableName, String rowId, List<ExtendedDataMutation> columns, Authorizations authorizations) throws IOException {
    XContentBuilder jsonBuilder;
    jsonBuilder = XContentFactory.jsonBuilder().startObject();
    String elementTypeString = ElasticsearchDocumentType.getExtendedDataDocumentTypeFromElement(element).getKey();
    jsonBuilder.field(ELEMENT_ID_FIELD_NAME, element.getId());
    jsonBuilder.field(ELEMENT_TYPE_FIELD_NAME, elementTypeString);
    String elementTypeVisibilityPropertyName = addElementTypeVisibilityPropertyToIndex(graph, element);
    jsonBuilder.field(elementTypeVisibilityPropertyName, elementTypeString);
    getConfig().getScoringStrategy().addFieldsToExtendedDataDocument(this, jsonBuilder, element, null, tableName, rowId, columns, authorizations);
    jsonBuilder.field(EXTENDED_DATA_TABLE_NAME_FIELD_NAME, tableName);
    jsonBuilder.field(EXTENDED_DATA_TABLE_ROW_ID_FIELD_NAME, rowId);
    if (element instanceof Edge) {
        Edge edge = (Edge) element;
        jsonBuilder.field(IN_VERTEX_ID_FIELD_NAME, edge.getVertexId(Direction.IN));
        jsonBuilder.field(OUT_VERTEX_ID_FIELD_NAME, edge.getVertexId(Direction.OUT));
        jsonBuilder.field(EDGE_LABEL_FIELD_NAME, edge.getLabel());
    }
    Map<String, Object> fields = getExtendedDataColumnsAsFields(graph, columns);
    addFieldsMap(jsonBuilder, fields);
    return jsonBuilder;
}
Also used : Edge(org.vertexium.Edge) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder)

Example 2 with Edge

use of org.vertexium.Edge in project vertexium by visallo.

the class Elasticsearch5SearchIndex method buildJsonContentFromElement.

private XContentBuilder buildJsonContentFromElement(Graph graph, Element element, Authorizations authorizations) throws IOException {
    XContentBuilder jsonBuilder;
    jsonBuilder = XContentFactory.jsonBuilder().startObject();
    String elementTypeVisibilityPropertyName = addElementTypeVisibilityPropertyToIndex(graph, element);
    jsonBuilder.field(ELEMENT_ID_FIELD_NAME, element.getId());
    jsonBuilder.field(ELEMENT_TYPE_FIELD_NAME, getElementTypeValueFromElement(element));
    if (element instanceof Vertex) {
        jsonBuilder.field(elementTypeVisibilityPropertyName, ElasticsearchDocumentType.VERTEX.getKey());
        getConfig().getScoringStrategy().addFieldsToVertexDocument(this, jsonBuilder, (Vertex) element, null, authorizations);
    } else if (element instanceof Edge) {
        Edge edge = (Edge) element;
        jsonBuilder.field(elementTypeVisibilityPropertyName, ElasticsearchDocumentType.EDGE.getKey());
        getConfig().getScoringStrategy().addFieldsToEdgeDocument(this, jsonBuilder, edge, null, authorizations);
        jsonBuilder.field(IN_VERTEX_ID_FIELD_NAME, edge.getVertexId(Direction.IN));
        jsonBuilder.field(OUT_VERTEX_ID_FIELD_NAME, edge.getVertexId(Direction.OUT));
        jsonBuilder.field(EDGE_LABEL_FIELD_NAME, edge.getLabel());
    } else {
        throw new VertexiumException("Unexpected element type " + element.getClass().getName());
    }
    for (Visibility hiddenVisibility : element.getHiddenVisibilities()) {
        String hiddenVisibilityPropertyName = addVisibilityToPropertyName(graph, HIDDEN_VERTEX_FIELD_NAME, hiddenVisibility);
        if (!isPropertyInIndex(graph, hiddenVisibilityPropertyName)) {
            String indexName = getIndexName(element);
            IndexInfo indexInfo = ensureIndexCreatedAndInitialized(graph, indexName);
            addPropertyToIndex(graph, indexInfo, hiddenVisibilityPropertyName, hiddenVisibility, Boolean.class, false, false, false);
        }
        jsonBuilder.field(hiddenVisibilityPropertyName, true);
    }
    Map<String, Object> fields = getPropertiesAsFields(graph, element.getProperties());
    addFieldsMap(jsonBuilder, fields);
    jsonBuilder.endObject();
    return jsonBuilder;
}
Also used : Edge(org.vertexium.Edge) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder)

Example 3 with Edge

use of org.vertexium.Edge in project vertexium by visallo.

the class Elasticsearch5SearchIndex method addElement.

@SuppressWarnings("unchecked")
@Override
public void addElement(Graph graph, Element element, Authorizations authorizations) {
    if (MUTATION_LOGGER.isTraceEnabled()) {
        MUTATION_LOGGER.trace("addElement: %s", element.getId());
    }
    if (!getConfig().isIndexEdges() && element instanceof Edge) {
        return;
    }
    if (flushObjectQueue.containsElementId(element.getId())) {
        flushObjectQueue.flush();
    }
    UpdateRequestBuilder updateRequestBuilder = prepareUpdate(graph, element, authorizations);
    addActionRequestBuilderForFlush(element.getId(), updateRequestBuilder);
    if (getConfig().isAutoFlush()) {
        flush(graph);
    }
}
Also used : UpdateRequestBuilder(org.elasticsearch.action.update.UpdateRequestBuilder) Edge(org.vertexium.Edge)

Example 4 with Edge

use of org.vertexium.Edge in project vertexium by visallo.

the class LabelsFunction method invoke.

@Override
public Object invoke(VertexiumCypherQueryContext ctx, CypherAstBase[] arguments, ExpressionScope scope) {
    CypherAstBase lookup = arguments[0];
    Object item = ctx.getExpressionExecutor().executeExpression(ctx, lookup, scope);
    if (item == null) {
        throw new VertexiumException("Could not find Vertex using " + lookup);
    }
    if (item instanceof Vertex) {
        Vertex vertex = (Vertex) item;
        return ctx.getVertexLabels(vertex);
    }
    if (item instanceof Edge) {
        Edge edge = (Edge) item;
        return Lists.newArrayList(edge.getLabel());
    }
    throw new VertexiumCypherTypeErrorException(item, Vertex.class, Edge.class);
}
Also used : Vertex(org.vertexium.Vertex) VertexiumCypherTypeErrorException(org.vertexium.cypher.exceptions.VertexiumCypherTypeErrorException) CypherAstBase(org.vertexium.cypher.ast.model.CypherAstBase) Edge(org.vertexium.Edge) VertexiumException(org.vertexium.VertexiumException)

Example 5 with Edge

use of org.vertexium.Edge in project vertexium by visallo.

the class Elasticsearch5SearchIndex method updateElement.

@Override
public <TElement extends Element> void updateElement(Graph graph, ExistingElementMutation<TElement> mutation, Authorizations authorizations) {
    TElement element = mutation.getElement();
    if (MUTATION_LOGGER.isTraceEnabled()) {
        MUTATION_LOGGER.trace("updateElement: %s", element.getId());
    }
    if (!getConfig().isIndexEdges() && element instanceof Edge) {
        return;
    }
    if (flushObjectQueue.containsElementId(element.getId())) {
        flushObjectQueue.flush();
    }
    UpdateRequestBuilder updateRequestBuilder = prepareUpdateForMutation(graph, mutation);
    if (updateRequestBuilder != null) {
        IndexInfo indexInfo = addMutationPropertiesToIndex(graph, mutation);
        getIndexRefreshTracker().pushChange(indexInfo.getIndexName());
        addActionRequestBuilderForFlush(element.getId(), updateRequestBuilder);
        if (getConfig().isAutoFlush()) {
            flush(graph);
        }
    }
}
Also used : UpdateRequestBuilder(org.elasticsearch.action.update.UpdateRequestBuilder) Edge(org.vertexium.Edge)

Aggregations

Edge (org.vertexium.Edge)6 UpdateRequestBuilder (org.elasticsearch.action.update.UpdateRequestBuilder)2 XContentBuilder (org.elasticsearch.common.xcontent.XContentBuilder)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 UpdateRequest (org.elasticsearch.action.update.UpdateRequest)1 ImmutableOpenMap (org.elasticsearch.common.collect.ImmutableOpenMap)1 Vertex (org.vertexium.Vertex)1 VertexiumException (org.vertexium.VertexiumException)1 CypherAstBase (org.vertexium.cypher.ast.model.CypherAstBase)1 VertexiumCypherTypeErrorException (org.vertexium.cypher.exceptions.VertexiumCypherTypeErrorException)1 ExtendedDataMutation (org.vertexium.mutation.ExtendedDataMutation)1