Search in sources :

Example 1 with HugeType

use of com.baidu.hugegraph.structure.constant.HugeType in project incubator-hugegraph-toolchain by apache.

the class BackupManager method doBackup.

public void doBackup(List<HugeType> types) {
    this.startTimer();
    for (HugeType type : types) {
        switch(type) {
            case VERTEX:
                this.backupVertices();
                break;
            case EDGE:
                this.backupEdges();
                break;
            case PROPERTY_KEY:
                this.backupPropertyKeys();
                break;
            case VERTEX_LABEL:
                this.backupVertexLabels();
                break;
            case EDGE_LABEL:
                this.backupEdgeLabels();
                break;
            case INDEX_LABEL:
                this.backupIndexLabels();
                break;
            default:
                throw new AssertionError(String.format("Bad backup type: %s", type));
        }
    }
    this.printSummary();
}
Also used : HugeType(com.baidu.hugegraph.structure.constant.HugeType)

Example 2 with HugeType

use of com.baidu.hugegraph.structure.constant.HugeType in project incubator-hugegraph-toolchain by apache.

the class PropertyIndexService method list.

/**
 * The sort result like that, content is 'name'
 * --------------+------------------------+---------------------------------
 * base_value    | index label name       | fields
 * --------------+------------------------+---------------------------------
 * xxxname       | xxxByName              | name
 * --------------+------------------------+---------------------------------
 *               | personByName           | name
 * person        +------------------------+---------------------------------
 *               | personByAgeAndName     | age name
 * --------------+------------------------+---------------------------------
 *               | softwareByName         | name
 * software      +------------------------+---------------------------------
 *               | softwareByPriveAndName | price name
 * --------------+------------------------+---------------------------------
 */
public IPage<PropertyIndex> list(int connId, HugeType type, String content, int pageNo, int pageSize) {
    HugeClient client = this.client(connId);
    List<IndexLabel> indexLabels = client.schema().getIndexLabels();
    Map<String, List<PropertyIndex>> matchedResults = new HashMap<>();
    Map<String, List<PropertyIndex>> unMatchResults = new HashMap<>();
    for (IndexLabel indexLabel : indexLabels) {
        if (!indexLabel.baseType().equals(type)) {
            continue;
        }
        String baseValue = indexLabel.baseValue();
        List<PropertyIndex> groupedIndexes;
        // Collect indexlabels that contains content
        boolean match = baseValue.contains(content);
        if (match) {
            groupedIndexes = matchedResults.computeIfAbsent(baseValue, k -> new ArrayList<>());
        } else {
            groupedIndexes = unMatchResults.computeIfAbsent(baseValue, k -> new ArrayList<>());
        }
        match = match || indexLabel.name().contains(content) || indexLabel.indexFields().stream().anyMatch(f -> f.contains(content));
        if (match) {
            groupedIndexes.add(convert(indexLabel));
        }
    }
    // Sort matched results by relevance
    if (!StringUtils.isEmpty(content)) {
        for (Map.Entry<String, List<PropertyIndex>> entry : matchedResults.entrySet()) {
            List<PropertyIndex> groupedIndexes = entry.getValue();
            groupedIndexes.sort(new Comparator<PropertyIndex>() {

                final int highScore = 2;

                final int lowScore = 1;

                @Override
                public int compare(PropertyIndex o1, PropertyIndex o2) {
                    int o1Score = 0;
                    if (o1.getName().contains(content)) {
                        o1Score += highScore;
                    }
                    if (o1.getFields().stream().anyMatch(field -> field.contains(content))) {
                        o1Score += lowScore;
                    }
                    int o2Score = 0;
                    if (o2.getName().contains(content)) {
                        o2Score += highScore;
                    }
                    if (o2.getFields().stream().anyMatch(field -> field.contains(content))) {
                        o2Score += lowScore;
                    }
                    return o2Score - o1Score;
                }
            });
        }
    }
    List<PropertyIndex> all = new ArrayList<>();
    matchedResults.values().forEach(all::addAll);
    unMatchResults.values().forEach(all::addAll);
    return PageUtil.page(all, pageNo, pageSize);
}
Also used : ServerException(com.baidu.hugegraph.exception.ServerException) BiFunction(java.util.function.BiFunction) SchemaEntity(com.baidu.hugegraph.entity.schema.SchemaEntity) HashMap(java.util.HashMap) PropertyIndex(com.baidu.hugegraph.entity.schema.PropertyIndex) ArrayList(java.util.ArrayList) Constant(com.baidu.hugegraph.common.Constant) Service(org.springframework.stereotype.Service) Map(java.util.Map) HugeClient(com.baidu.hugegraph.driver.HugeClient) Collection(java.util.Collection) ConflictDetail(com.baidu.hugegraph.entity.schema.ConflictDetail) IndexLabel(com.baidu.hugegraph.structure.schema.IndexLabel) ConflictStatus(com.baidu.hugegraph.entity.schema.ConflictStatus) Collectors(java.util.stream.Collectors) HugeType(com.baidu.hugegraph.structure.constant.HugeType) List(java.util.List) CollectionUtils(org.springframework.util.CollectionUtils) SchemaConflict(com.baidu.hugegraph.entity.schema.SchemaConflict) SchemaType(com.baidu.hugegraph.entity.schema.SchemaType) Log4j2(lombok.extern.log4j.Log4j2) PageUtil(com.baidu.hugegraph.util.PageUtil) Comparator(java.util.Comparator) Collections(java.util.Collections) IPage(com.baomidou.mybatisplus.core.metadata.IPage) StringUtils(org.springframework.util.StringUtils) HugeClient(com.baidu.hugegraph.driver.HugeClient) HashMap(java.util.HashMap) IndexLabel(com.baidu.hugegraph.structure.schema.IndexLabel) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) PropertyIndex(com.baidu.hugegraph.entity.schema.PropertyIndex)

Example 3 with HugeType

use of com.baidu.hugegraph.structure.constant.HugeType in project incubator-hugegraph-toolchain by apache.

the class RestoreManager method doRestore.

public void doRestore(List<HugeType> types) {
    E.checkNotNull(this.mode, "mode");
    this.startTimer();
    for (HugeType type : types) {
        switch(type) {
            case VERTEX:
                this.restoreVertices(type);
                break;
            case EDGE:
                this.restoreEdges(type);
                break;
            case PROPERTY_KEY:
                this.restorePropertyKeys(type);
                break;
            case VERTEX_LABEL:
                this.restoreVertexLabels(type);
                break;
            case EDGE_LABEL:
                this.restoreEdgeLabels(type);
                break;
            case INDEX_LABEL:
                this.restoreIndexLabels(type);
                break;
            default:
                throw new AssertionError(String.format("Bad restore type: %s", type));
        }
    }
    this.printSummary();
    if (this.clean) {
        this.removeDirectory();
    }
}
Also used : HugeType(com.baidu.hugegraph.structure.constant.HugeType)

Aggregations

HugeType (com.baidu.hugegraph.structure.constant.HugeType)3 Constant (com.baidu.hugegraph.common.Constant)1 HugeClient (com.baidu.hugegraph.driver.HugeClient)1 ConflictDetail (com.baidu.hugegraph.entity.schema.ConflictDetail)1 ConflictStatus (com.baidu.hugegraph.entity.schema.ConflictStatus)1 PropertyIndex (com.baidu.hugegraph.entity.schema.PropertyIndex)1 SchemaConflict (com.baidu.hugegraph.entity.schema.SchemaConflict)1 SchemaEntity (com.baidu.hugegraph.entity.schema.SchemaEntity)1 SchemaType (com.baidu.hugegraph.entity.schema.SchemaType)1 ServerException (com.baidu.hugegraph.exception.ServerException)1 IndexLabel (com.baidu.hugegraph.structure.schema.IndexLabel)1 PageUtil (com.baidu.hugegraph.util.PageUtil)1 IPage (com.baomidou.mybatisplus.core.metadata.IPage)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 Comparator (java.util.Comparator)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1