Search in sources :

Example 16 with LindenSchema

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

Example 17 with LindenSchema

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

Example 18 with LindenSchema

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());
}
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 19 with LindenSchema

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

Example 20 with LindenSchema

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

Aggregations

LindenSchema (com.xiaomi.linden.thrift.common.LindenSchema)21 LindenFieldSchema (com.xiaomi.linden.thrift.common.LindenFieldSchema)17 File (java.io.File)5 Test (org.junit.Test)3 LindenConfig (com.xiaomi.linden.core.LindenConfig)1 LindenIndexRequest (com.xiaomi.linden.thrift.common.LindenIndexRequest)1 IOException (java.io.IOException)1 DocumentBuilder (javax.xml.parsers.DocumentBuilder)1 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)1 Document (org.w3c.dom.Document)1 Element (org.w3c.dom.Element)1 Node (org.w3c.dom.Node)1 NodeList (org.w3c.dom.NodeList)1