Search in sources :

Example 6 with LindenIndexRequest

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());
}
Also used : LindenSchema(com.xiaomi.linden.thrift.common.LindenSchema) LindenIndexRequest(com.xiaomi.linden.thrift.common.LindenIndexRequest) File(java.io.File) Test(org.junit.Test)

Example 7 with LindenIndexRequest

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);
}
Also used : LindenIndexRequest(com.xiaomi.linden.thrift.common.LindenIndexRequest)

Aggregations

LindenIndexRequest (com.xiaomi.linden.thrift.common.LindenIndexRequest)7 IOException (java.io.IOException)3 Response (com.xiaomi.linden.thrift.common.Response)2 Stopwatch (com.google.common.base.Stopwatch)1 Future (com.twitter.util.Future)1 FutureTransformer (com.twitter.util.FutureTransformer)1 IntermediateForm (com.xiaomi.linden.hadoop.indexing.keyvalueformat.IntermediateForm)1 LindenSchema (com.xiaomi.linden.thrift.common.LindenSchema)1 File (java.io.File)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ExecutionException (java.util.concurrent.ExecutionException)1 Document (org.apache.lucene.document.Document)1 Term (org.apache.lucene.index.Term)1 Test (org.junit.Test)1