use of com.xiaomi.linden.thrift.common.LindenIndexRequest in project linden by XiaoMi.
the class TestLindenIndexRequestParser method basicTest.
@Test
public void basicTest() throws Exception {
String content = "{\"id\":\"18617\"," + "\"sName\":\"杭州萧山明达园艺场\"," + "\"catId\":4," + "\"latitude\":0," + "\"longitude\":0" + "}";
String schemaXml = TestLindenIndexRequestParser.class.getClassLoader().getResource("service1/schema.xml").getFile();
LindenSchema schema = LindenSchemaBuilder.build(new File(schemaXml));
LindenIndexRequest request = LindenIndexRequestParser.parse(schema, content);
Assert.assertEquals(IndexRequestType.INDEX, request.getType());
Assert.assertEquals(4, request.getDoc().getFieldsSize());
// miss field.
content = "{\"id\":\"18617\"," + "\"sName\":\"杭州萧山明达园艺场\"," + "\"catId\":4," + "\"latitude\":0," + "\"longitude\":0," + "}";
request = LindenIndexRequestParser.parse(schema, content);
Assert.assertEquals(IndexRequestType.INDEX, request.getType());
Assert.assertEquals(4, request.getDoc().getFieldsSize());
// index type
content = "{\"type\":\"index\"," + "\"content\":{\"id\":\"18617\",\"sName\":\"杭州萧山明达园艺场\",\"catId\":4,\"latitude\":0,\"longitude\":0}" + "}";
request = LindenIndexRequestParser.parse(schema, content);
Assert.assertEquals(IndexRequestType.INDEX, request.getType());
Assert.assertEquals(4, request.getDoc().getFieldsSize());
// index request with route param
content = "{\"type\":\"index\"," + "\"route\":[0,1,2]," + "\"content\":{\"id\":\"18617\",\"sName\":\"杭州萧山明达园艺场\",\"catId\":4,\"latitude\":0,\"longitude\":0}" + "}";
request = LindenIndexRequestParser.parse(schema, content);
Assert.assertEquals(IndexRequestType.INDEX, request.getType());
Assert.assertEquals(3, request.getRouteParam().getShardIdsSize());
Assert.assertEquals(4, request.getDoc().getFieldsSize());
// delete request
content = "{\"type\":\"delete\", \"id\":\"123\"}";
request = LindenIndexRequestParser.parse(schema, content);
Assert.assertEquals(IndexRequestType.DELETE, request.getType());
Assert.assertEquals("123", request.getId());
// delete request with route param
content = "{\"type\":\"delete\", \"route\":[0,1,2], \"id\":\"123\"}";
request = LindenIndexRequestParser.parse(schema, content);
Assert.assertEquals(IndexRequestType.DELETE, request.getType());
Assert.assertEquals("123", request.getId());
Assert.assertEquals(3, request.getRouteParam().getShardIdsSize());
}
use of com.xiaomi.linden.thrift.common.LindenIndexRequest in project linden by XiaoMi.
the class TestMultiLindenCore method handleRequest.
public void handleRequest(String content) throws IOException {
LindenIndexRequest indexRequest = LindenIndexRequestParser.parse(lindenConfig.getSchema(), content);
lindenCore.index(indexRequest);
}
Aggregations