Search in sources :

Example 6 with LindenSchema

use of com.xiaomi.linden.thrift.common.LindenSchema in project linden by XiaoMi.

the class TestGlobalIDF 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).setOmitNorms(true));
    schema.addToFields(new LindenFieldSchema().setName("field1").setIndexed(true).setStored(true).setTokenized(true).setOmitNorms(true));
    schema.addToFields(new LindenFieldSchema().setName("field2").setIndexed(true).setStored(true).setTokenized(true).setOmitNorms(true));
    schema.addToFields(new LindenFieldSchema().setName("rank").setType(LindenType.FLOAT).setIndexed(true).setStored(true));
    schema.addToFields(new LindenFieldSchema().setName("cat1").setType(LindenType.INTEGER).setIndexed(true).setStored(true));
    schema.addToFields(new LindenFieldSchema().setName("cat2").setType(LindenType.DOUBLE).setIndexed(true).setStored(true));
    schema.addToFields(new LindenFieldSchema().setName("tagstr").setIndexed(true));
    schema.addToFields(new LindenFieldSchema().setName("tagnum").setType(LindenType.INTEGER).setIndexed(true));
    lindenConfig.setSchema(schema);
}
Also used : LindenFieldSchema(com.xiaomi.linden.thrift.common.LindenFieldSchema) LindenSchema(com.xiaomi.linden.thrift.common.LindenSchema)

Example 7 with LindenSchema

use of com.xiaomi.linden.thrift.common.LindenSchema in project linden by XiaoMi.

the class LindenConfigBuilder method build.

public static LindenConfig build() throws IOException {
    File lindenProperties = new File("lindenProperties");
    Preconditions.checkArgument(lindenProperties.exists(), "can not find linden properties file.");
    try {
        LindenConfig lindenConf = com.xiaomi.linden.core.LindenConfigBuilder.build(lindenProperties);
        File lindenSchema = new File("lindenSchema");
        Preconditions.checkArgument(lindenSchema.exists(), "can not find linden schema file.");
        LindenSchema schema;
        try {
            schema = LindenSchemaBuilder.build(lindenSchema);
        } catch (Exception e) {
            logger.error("Linden schema builder exception", e);
            throw new IOException(e);
        }
        lindenConf.setSchema(schema);
        lindenConf.setIndexType(LindenConfig.IndexType.RAM);
        return lindenConf;
    } catch (Exception e) {
        logger.error("Linden search config builder exception", e);
        throw new IOException(e);
    }
}
Also used : LindenConfig(com.xiaomi.linden.core.LindenConfig) LindenSchema(com.xiaomi.linden.thrift.common.LindenSchema) IOException(java.io.IOException) File(java.io.File) IOException(java.io.IOException)

Example 8 with LindenSchema

use of com.xiaomi.linden.thrift.common.LindenSchema in project linden by XiaoMi.

the class LindenSchemaBuilder method build.

public static LindenSchema build(File schemaFile) throws Exception {
    Preconditions.checkNotNull(schemaFile);
    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    DocumentBuilder db = dbf.newDocumentBuilder();
    Document dom = db.parse(schemaFile);
    dom.getDocumentElement().normalize();
    NodeList table = dom.getElementsByTagName(TABLE);
    Node colNode = table.item(0);
    LindenSchema lindenSchema = new LindenSchema();
    lindenSchema.setId(colNode.getAttributes().getNamedItem(TABLE_ID).getNodeValue());
    NodeList colList = dom.getElementsByTagName(TABLE_COLUMN);
    for (int i = 0; i < colList.getLength(); ++i) {
        Element element = (Element) colList.item(i);
        LindenFieldSchema fieldSchema = parseFiled(element);
        verifyFieldSchema(fieldSchema);
        lindenSchema.addToFields(fieldSchema);
    }
    return lindenSchema;
}
Also used : LindenFieldSchema(com.xiaomi.linden.thrift.common.LindenFieldSchema) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) LindenSchema(com.xiaomi.linden.thrift.common.LindenSchema) DocumentBuilder(javax.xml.parsers.DocumentBuilder) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) Element(org.w3c.dom.Element) Document(org.w3c.dom.Document)

Example 9 with LindenSchema

use of com.xiaomi.linden.thrift.common.LindenSchema in project linden by XiaoMi.

the class TestLindenWordDelimiterAnalyzer method init.

@Override
public void init() {
    lindenConfig.setIndexType(LindenConfig.IndexType.RAM);
    lindenConfig.setClusterUrl("127.0.0.1:2181/mock");
    LindenSchema schema = new LindenSchema().setId("id");
    schema.addToFields(new LindenFieldSchema().setName("title").setIndexed(true).setTokenized(true).setSnippet(true).setMulti(true));
    lindenConfig.setSchema(schema);
    lindenConfig.putToProperties("search.analyzer.class", "com.xiaomi.linden.lucene.analyzer.LindenWordDelimiterAnalyzerFactory");
    lindenConfig.putToProperties("index.analyzer.class", "com.xiaomi.linden.lucene.analyzer.LindenWordDelimiterAnalyzerFactory");
    lindenConfig.putToProperties("index.analyzer.luceneMatchVersion", "LUCENE_4_10_0");
    lindenConfig.putToProperties("search.analyzer.luceneMatchVersion", "LUCENE_4_10_0");
}
Also used : LindenFieldSchema(com.xiaomi.linden.thrift.common.LindenFieldSchema) LindenSchema(com.xiaomi.linden.thrift.common.LindenSchema)

Example 10 with LindenSchema

use of com.xiaomi.linden.thrift.common.LindenSchema in project linden by XiaoMi.

the class TestFlexibleQuery method init.

@Override
public void init() throws Exception {
    LindenSchema schema = new LindenSchema().setId("id");
    schema.addToFields(new LindenFieldSchema().setName("text").setIndexed(true).setStored(true).setTokenized(true));
    schema.addToFields(new LindenFieldSchema().setName("title").setIndexed(true).setStored(true).setTokenized(true));
    lindenConfig.setSchema(schema);
}
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