use of com.baidu.hugegraph.structure.schema.IndexLabel in project incubator-hugegraph-toolchain by apache.
the class PropertyIndexService method list.
public IPage<PropertyIndex> list(int connId, HugeType type, int pageNo, int pageSize) {
HugeClient client = this.client(connId);
List<IndexLabel> indexLabels = client.schema().getIndexLabels();
List<PropertyIndex> results = new ArrayList<>();
for (IndexLabel indexLabel : indexLabels) {
if (!indexLabel.baseType().equals(type)) {
continue;
}
// Collect all indexlabels
results.add(convert(indexLabel));
}
// Sort by owner name a-z, then index name a-z
results.sort((o1, o2) -> {
String owner1 = o1.getOwner();
String owner2 = o2.getOwner();
if (!owner1.equals(owner2)) {
return owner1.compareTo(owner2);
}
return o1.getName().compareTo(o2.getName());
});
return PageUtil.page(results, pageNo, pageSize);
}
use of com.baidu.hugegraph.structure.schema.IndexLabel 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);
}
use of com.baidu.hugegraph.structure.schema.IndexLabel in project incubator-hugegraph-toolchain by apache.
the class EdgeLabelService method get.
public EdgeLabelEntity get(String name, int connId) {
HugeClient client = this.client(connId);
try {
EdgeLabel edgeLabel = client.schema().getEdgeLabel(name);
List<IndexLabel> indexLabels = client.schema().getIndexLabels();
return convert(edgeLabel, indexLabels);
} catch (ServerException e) {
if (e.status() == Constant.STATUS_NOT_FOUND) {
throw new ExternalException("schema.edgelabel.not-exist", e, name);
}
throw new ExternalException("schema.edgelabel.get.failed", e, name);
}
}
use of com.baidu.hugegraph.structure.schema.IndexLabel in project incubator-hugegraph-toolchain by apache.
the class SchemaService method addBatch.
public static <T extends SchemaElement> void addBatch(List<T> schemas, HugeClient client, BiConsumer<HugeClient, T> func, SchemaType type) {
if (CollectionUtils.isEmpty(schemas)) {
return;
}
Date now = HubbleUtil.nowDate();
for (T schema : schemas) {
schema.resetId();
if (!(schema instanceof IndexLabel)) {
schema.userdata().put(USER_KEY_CREATE_TIME, now);
}
func.accept(client, schema);
}
}
use of com.baidu.hugegraph.structure.schema.IndexLabel in project incubator-hugegraph-toolchain by apache.
the class SchemaService method addBatch.
public static <T extends SchemaElement> List<Long> addBatch(List<T> schemas, HugeClient client, BiFunction<HugeClient, T, Long> func, SchemaType type) {
List<Long> tasks = new ArrayList<>();
if (CollectionUtils.isEmpty(schemas)) {
return tasks;
}
Date now = HubbleUtil.nowDate();
for (T schema : schemas) {
schema.resetId();
if (!(schema instanceof IndexLabel)) {
schema.userdata().put(USER_KEY_CREATE_TIME, now);
}
tasks.add(func.apply(client, schema));
}
return tasks;
}
Aggregations