use of com.baidu.hugegraph.structure.schema.IndexLabel in project incubator-hugegraph-toolchain by apache.
the class IndexLabelAPI method create.
public IndexLabel.IndexLabelWithTask create(IndexLabel indexLabel) {
Object il = this.checkCreateOrUpdate(indexLabel);
RestResult result = this.client.post(this.path(), il);
return result.readObject(IndexLabel.IndexLabelWithTask.class);
}
use of com.baidu.hugegraph.structure.schema.IndexLabel in project incubator-hugegraph-toolchain by apache.
the class RestResultTest method testReadIndexLabel.
@Test
public void testReadIndexLabel() {
String json = "{" + "\"id\": \"4\"," + "\"index_type\": \"SEARCH\"," + "\"base_value\": \"software\"," + "\"name\": \"softwareByPrice\"," + "\"fields\": [\"price\"]," + "\"base_type\": \"VERTEX_LABEL\"" + "}";
Mockito.when(this.mockResponse.getStatus()).thenReturn(200);
Mockito.when(this.mockResponse.getHeaders()).thenReturn(null);
Mockito.when(this.mockResponse.readEntity(String.class)).thenReturn(json);
RestResult result = new RestResult(this.mockResponse);
Assert.assertEquals(200, result.status());
Assert.assertNull(result.headers());
IndexLabel indexLabel = result.readObject(IndexLabel.class);
Assert.assertEquals("softwareByPrice", indexLabel.name());
Assert.assertEquals(HugeType.VERTEX_LABEL, indexLabel.baseType());
Assert.assertEquals("software", indexLabel.baseValue());
Assert.assertEquals(IndexType.SEARCH, indexLabel.indexType());
Assert.assertEquals(ImmutableList.of("price"), indexLabel.indexFields());
}
use of com.baidu.hugegraph.structure.schema.IndexLabel in project incubator-hugegraph-toolchain by apache.
the class IndexLabelTest method testAppendIndexLabelWithUserData.
@Test
public void testAppendIndexLabelWithUserData() {
SchemaManager schema = schema();
BaseFuncTest.initVertexLabel();
IndexLabel personByCity = schema.indexLabel("personByCity").onV("person").by("city").secondary().ifNotExist().create();
Assert.assertEquals(1, personByCity.userdata().size());
String time = (String) personByCity.userdata().get("~create_time");
Date createTime = DateUtil.parse(time);
Assert.assertTrue(createTime.before(DateUtil.now()));
personByCity = schema.indexLabel("personByCity").userdata("type", "secondary").append();
Assert.assertEquals(2, personByCity.userdata().size());
Assert.assertEquals("secondary", personByCity.userdata().get("type"));
time = (String) personByCity.userdata().get("~create_time");
Assert.assertEquals(createTime, DateUtil.parse(time));
}
use of com.baidu.hugegraph.structure.schema.IndexLabel in project incubator-hugegraph-toolchain by apache.
the class IndexLabelTest method testAddIndexLabelAsync.
@Test
public void testAddIndexLabelAsync() {
SchemaManager schema = schema();
schema.vertexLabel("player").properties("name", "age").create();
IndexLabel playerByName = schema.indexLabel("playerByName").onV("player").by("name").secondary().build();
long task = schema.addIndexLabelAsync(playerByName);
waitUntilTaskCompleted(task);
playerByName = schema.getIndexLabel(playerByName.name());
Assert.assertNotNull(playerByName);
}
use of com.baidu.hugegraph.structure.schema.IndexLabel in project incubator-hugegraph-toolchain by apache.
the class IndexLabelTest method testEliminateIndexLabelWithUserData.
@Test
public void testEliminateIndexLabelWithUserData() {
SchemaManager schema = schema();
BaseFuncTest.initVertexLabel();
IndexLabel personByCity = schema.indexLabel("personByCity").onV("person").by("city").secondary().userdata("type", "secondary").userdata("icon", "picture").ifNotExist().create();
Assert.assertEquals(3, personByCity.userdata().size());
Assert.assertEquals("secondary", personByCity.userdata().get("type"));
Assert.assertEquals("picture", personByCity.userdata().get("icon"));
String time = (String) personByCity.userdata().get("~create_time");
Date createTime = DateUtil.parse(time);
Assert.assertTrue(createTime.before(DateUtil.now()));
personByCity = schema.indexLabel("personByCity").userdata("type", "secondary").eliminate();
Assert.assertEquals(2, personByCity.userdata().size());
Assert.assertEquals("picture", personByCity.userdata().get("icon"));
time = (String) personByCity.userdata().get("~create_time");
Assert.assertEquals(createTime, DateUtil.parse(time));
}
Aggregations