use of com.xiaomi.linden.thrift.common.LindenSchema in project linden by XiaoMi.
the class TestLindenGroupSearch method init.
@Override
public void init() throws Exception {
LindenSchema schema = new LindenSchema().setId("id");
schema.addToFields(new LindenFieldSchema().setName("title").setIndexed(true).setStored(true).setTokenized(true));
schema.addToFields(new LindenFieldSchema().setName("field1").setIndexed(true).setStored(false));
schema.addToFields(new LindenFieldSchema().setName("rank").setType(LindenType.FLOAT).setIndexed(true).setStored(true));
schema.addToFields(new LindenFieldSchema().setName("cat1").setIndexed(true).setStored(true));
lindenConfig.setSchema(schema);
}
use of com.xiaomi.linden.thrift.common.LindenSchema in project linden by XiaoMi.
the class TestLindenIndexRequestParser method exceptionTest.
@Test(expected = Exception.class)
public void exceptionTest() throws Exception {
// no id
String content = "{\"sName\":\"杭州萧山明达园艺场\",\"catId\":4,\"latitude\":0,\"longitude\":0}";
String schemaXml = TestLindenIndexRequestParser.class.getClassLoader().getResource("service1/schema.xml").getFile();
LindenSchema schema = LindenSchemaBuilder.build(new File(schemaXml));
LindenIndexRequestParser.parse(schema, content);
}
use of com.xiaomi.linden.thrift.common.LindenSchema 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.LindenSchema in project linden by XiaoMi.
the class TestLindenSchemaBuilder method lindenSchemaBuilderTest.
@Test
public void lindenSchemaBuilderTest() throws Exception {
String schemaPath = TestLindenSchemaBuilder.class.getResource("/test_builder_schema.xml").getPath();
LindenSchema schema = LindenSchemaBuilder.build(new File(schemaPath));
Assert.assertEquals("aid", schema.getId());
Assert.assertEquals(9, schema.getFieldsSize());
Assert.assertTrue(schema.getFields().get(0).isSnippet());
Assert.assertTrue(schema.getFields().get(0).isOmitFreqs());
Assert.assertTrue(schema.getFields().get(1).isIndexed());
Assert.assertFalse(schema.getFields().get(6).isIndexed());
Assert.assertEquals(LindenType.STRING, schema.getFields().get(5).getType());
Assert.assertEquals(LindenType.FACET, schema.getFields().get(8).getType());
}
use of com.xiaomi.linden.thrift.common.LindenSchema in project linden by XiaoMi.
the class TestLindenSnippet method init.
@Override
public void init() throws Exception {
LindenSchema schema = new LindenSchema().setId("id");
schema.addToFields(new LindenFieldSchema().setName("title").setTokenized(true).setIndexed(true).setSnippet(true));
schema.addToFields(new LindenFieldSchema().setName("body").setTokenized(true).setIndexed(true).setSnippet(true));
lindenConfig.setSchema(schema);
lindenConfig.setSearchAnalyzer("com.xiaomi.linden.lucene.analyzer.LindenMMSeg4jAnalyzerFactory");
lindenConfig.setIndexAnalyzer("com.xiaomi.linden.lucene.analyzer.LindenMMSeg4jAnalyzerFactory");
lindenConfig.putToProperties("search.analyzer.class", "com.xiaomi.linden.lucene.analyzer.LindenMMSeg4jAnalyzerFactory");
lindenConfig.putToProperties("search.analyzer.unique", "false");
lindenConfig.putToProperties("index.analyzer.class", "com.xiaomi.linden.lucene.analyzer.LindenMMSeg4jAnalyzerFactory");
lindenConfig.putToProperties("index.analyzer.unique", "false");
}
Aggregations