Search in sources :

Example 1 with PSchemaField

use of com.qlangtech.tis.solrdao.pojo.PSchemaField in project tis by qlangtech.

the class ParseResult method addReservedFields.

/**
 * 添加保留字段
 */
public void addReservedFields() {
    SolrFieldsParser.SolrType strType = this.getTisType(ReflectSchemaFieldType.STRING.literia);
    SolrFieldsParser.SolrType longType = this.getTisType("long");
    PSchemaField verField = new PSchemaField();
    verField.setName("_version_");
    verField.setDocValue(true);
    verField.setStored(true);
    verField.setType(longType);
    this.dFields.add(verField);
    PSchemaField textField = new PSchemaField();
    textField.setName("text");
    textField.setDocValue(false);
    textField.setMltiValued(true);
    textField.setStored(false);
    textField.setIndexed(true);
    textField.setType(strType);
    this.dFields.add(textField);
}
Also used : PSchemaField(com.qlangtech.tis.solrdao.pojo.PSchemaField) SolrFieldsParser(com.qlangtech.tis.solrdao.SolrFieldsParser)

Example 2 with PSchemaField

use of com.qlangtech.tis.solrdao.pojo.PSchemaField in project tis by qlangtech.

the class IndexQueryAction method doGetServerNodes.

/**
 * @param context
 */
public void doGetServerNodes(Context context) throws Exception {
    AppDomainInfo domain = this.getAppDomain();
    if (domain instanceof Nullable) {
        throw new IllegalStateException("execute phase must be Collection aware");
    }
    QueryResutStrategy queryStrategy = QueryIndexServlet.createQueryResutStrategy(domain, new QueryRequestWrapper(getRequest(), context), getResponse(), getDaoContext());
    List<ServerJoinGroup> nodes = queryStrategy.queryProcess();
    List<PSchemaField> sfields = IndexQuery.getSfields(this.getRequest(), queryStrategy, nodes);
    Map<String, Object> props = Maps.newHashMap();
    props.put("nodes", queryStrategy.selectCandiate);
    props.put("fields", sfields.stream().map((c) -> c.getName()).collect(Collectors.toList()));
    this.setBizResult(context, props);
}
Also used : AppDomainInfo(com.qlangtech.tis.manage.common.AppDomainInfo) PSchemaField(com.qlangtech.tis.solrdao.pojo.PSchemaField) QueryRequestWrapper(com.qlangtech.tis.runtime.module.screen.IndexQuery.QueryRequestWrapper) Nullable(com.qlangtech.tis.pubhook.common.Nullable)

Example 3 with PSchemaField

use of com.qlangtech.tis.solrdao.pojo.PSchemaField in project tis by qlangtech.

the class CollectionAction method doGetIndexTopology.

/**
 * @param context
 * @throws Exception
 */
public void doGetIndexTopology(Context context) throws Exception {
    this.getIndexWithPost();
    JSONObject biz = new JSONObject();
    CollectionTopology topology = CoreAction.getCollectionTopology(this);
    JSONArray shards = new JSONArray();
    JSONObject shard = null;
    JSONArray replics = null;
    JSONObject replic = null;
    for (CollectionTopology.Shared s : topology.getShareds()) {
        shard = new JSONObject();
        replics = new JSONArray();
        shard.put(KEY_SHARD_NAME, s.getName());
        for (Replica r : s.getReplics()) {
            replic = new JSONObject();
            replic.put(KEY_CORE_URL, r.getCoreUrl());
            replic.put(KEY_IS_ACTIVE, r.getState() == Replica.State.ACTIVE);
            replics.add(replic);
        }
        shard.put(KEY_REPLICS, replics);
        shards.add(shard);
    }
    biz.put(SqlTaskNodeMeta.KEY_PROFILE_TOPOLOGY, shards);
    SnapshotDomain snapshot = ViewPojo.getSnapshotDoamin(this, this.getAppDomain());
    ParseResult parseResult = SolrFieldsParser.parse(() -> {
        return snapshot.getSolrSchema().getContent();
    }).getSchemaParseResult();
    biz.put(KEY_PK, parseResult.getUniqueKey());
    QueryResutStrategy queryStrategy = QueryIndexServlet.createQueryResutStrategy(this.getAppDomain(), new IndexQuery.QueryRequestWrapper(getRequest(), context), getResponse(), getDaoContext());
    List<ServerJoinGroup> nodes = queryStrategy.queryProcess();
    List<PSchemaField> sfields = IndexQuery.getSfields(this.getRequest(), queryStrategy, nodes);
    JSONArray colsMeta = new JSONArray();
    JSONObject colmeta = null;
    for (PSchemaField field : sfields) {
        colmeta = new JSONObject();
        colmeta.put("name", field.getName());
        colmeta.put("typeName", field.getType().getJavaType().getSimpleName());
        colmeta.put("typeCode", field.getType().getJavaType().getTypeCode());
        colmeta.put("docval", field.isDocValue());
        colmeta.put("indexd", field.isIndexed());
        colmeta.put("stored", field.isStored());
        colmeta.put("dynamic", field.isDynamic());
        colsMeta.add(colmeta);
    }
    biz.put(KEY_COLS_META, colsMeta);
    this.setBizResult(context, biz);
}
Also used : QueryResutStrategy(com.qlangtech.tis.manage.servlet.QueryResutStrategy) IndexQuery(com.qlangtech.tis.runtime.module.screen.IndexQuery) ParseResult(com.qlangtech.tis.solrdao.impl.ParseResult) PSchemaField(com.qlangtech.tis.solrdao.pojo.PSchemaField) JSONArray(com.alibaba.fastjson.JSONArray) ServerJoinGroup(com.qlangtech.tis.manage.servlet.ServerJoinGroup) Replica(org.apache.solr.common.cloud.Replica) JSONObject(com.alibaba.fastjson.JSONObject)

Example 4 with PSchemaField

use of com.qlangtech.tis.solrdao.pojo.PSchemaField in project tis by qlangtech.

the class SchemaAction method createSchema.

/**
 * Schema XML模式 --> 专家模式 是一个数据结构投影,确保XML转专家模式,再专家模式转xml模式信息不会减少
 */
protected String createSchema(ISchemaPluginContext schemaPlugin, UploadSchemaWithRawContentForm schemaForm, boolean shallExecuteDelete) throws Exception {
    Assert.assertNotNull(schemaForm);
    // 先解析库中已经存在的模板
    if (StringUtils.isBlank(schemaForm.getSchemaXmlContent())) {
        throw new IllegalArgumentException("schemaXmlContent can not be null");
    }
    // 原始内容
    final byte[] originContent = schemaForm.getSchemaXmlContent().getBytes(getEncode());
    org.w3c.dom.Document document = createDocument(originContent);
    ParseResult parseResult = SolrFieldsParser.parseDocument(document, schemaPlugin, false);
    byte[] modifiedContent = XModifier.modifySchemaContent(originContent, (document2, modifier) -> {
        for (PSchemaField field : parseResult.dFields) {
            // 小白编辑模式下可能将字段删除,所以在高级模式下也要将字段删除
            if (schemaForm.containsField(field.getName())) {
                // intersectionKeys.add(field.getName());
                continue;
            }
            if (shallExecuteDelete) {
                if (field.isDynamic()) {
                    modifier.addModify("/fields/dynamicField[@name='" + field.getName() + "'](:delete)");
                } else {
                    modifier.addModify("/fields/field[@name='" + field.getName() + "'](:delete)");
                }
            }
        }
        updateSchemaXML(parseResult.types, schemaPlugin, schemaForm, document2, modifier);
        DocType docType = new DocType("schema", "solrres://tisrepository/dtd/solrschema.dtd");
        document2.setDocType(docType);
    });
    return new String(modifiedContent, TisUTF8.get());
}
Also used : ParseResult(com.qlangtech.tis.solrdao.impl.ParseResult) PSchemaField(com.qlangtech.tis.solrdao.pojo.PSchemaField) DocType(org.jdom2.DocType)

Example 5 with PSchemaField

use of com.qlangtech.tis.solrdao.pojo.PSchemaField in project tis by qlangtech.

the class SolrFieldsParser method parseField.

private ParseResult parseField(Document document, boolean shallValidate, final XPath xpath, ParseResult parseResult, final ArrayList<PSchemaField> dFields, String expression, boolean dynamicField) throws Exception {
    NodeList nodes;
    nodes = (NodeList) xpath.evaluate(expression, document, XPathConstants.NODESET);
    PSchemaField field = null;
    Matcher matcher = null;
    for (int i = 0; i < nodes.getLength(); i++) {
        // new PSchemaField();
        field = new PSchemaField();
        field.setDynamic(dynamicField);
        Node node = nodes.item(i);
        NamedNodeMap attrs = node.getAttributes();
        String name = DOMUtil.getAttr(attrs, "name", "field definition");
        matcher = SPACE.matcher(name);
        if (shallValidate && matcher.find()) {
            // parseResult.errlist.add("name:" + name + " can not contain
            // space word");
            parseResult.errlist.add("字段名称:‘" + name + "’中不能有空格");
            return parseResult;
        }
        field.setName(name);
        String typeKey = DOMUtil.getAttr(attrs, "type", "field " + name);
        SolrType type = parseResult.types.get(typeKey);
        // + " is not define in fieldtypes", type);
        if (shallValidate && type == null) {
            // parseResult.errlist.add("typeKey:" + typeKey + " is not
            // define in fieldtypes");
            // parseResult.errlist.add("typeKey:" + typeKey + " is not
            // define in fieldtypes");
            parseResult.errlist.add("字段类型:‘" + typeKey + "’在已有类型中不存在");
            return parseResult;
        }
        if (!shallValidate && type == null) {
            type = parseFieldType(typeKey, typeKey);
        }
        field.setType(type);
        Map<String, String> args = DOMUtil.toMapExcept(attrs, "name", "type");
        if (args.get("required") != null) {
            field.setRequired(Boolean.valueOf(args.get("required")));
        }
        if (args.get("indexed") != null) {
            field.setIndexed(Boolean.valueOf(args.get("indexed")));
        }
        if (args.get("stored") != null) {
            field.setStored(Boolean.valueOf(args.get("stored")));
        }
        if (args.get("multiValued") != null) {
            field.setMltiValued(Boolean.valueOf(args.get("multiValued")));
        }
        if (args.get("docValues") != null) {
            field.setDocValue(Boolean.valueOf(args.get("docValues")));
        }
        if (args.get("useDocValuesAsStored") != null) {
            field.setUseDocValuesAsStored(Boolean.valueOf(args.get("useDocValuesAsStored")));
        }
        if (args.get("default") != null) {
            field.setDefaultValue(args.get("default"));
        }
        parseResult.dFieldsNames.add(field.getName());
        dFields.add(field);
    }
    return parseResult;
}
Also used : NamedNodeMap(org.w3c.dom.NamedNodeMap) PSchemaField(com.qlangtech.tis.solrdao.pojo.PSchemaField) Matcher(java.util.regex.Matcher) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node)

Aggregations

PSchemaField (com.qlangtech.tis.solrdao.pojo.PSchemaField)11 ParseResult (com.qlangtech.tis.solrdao.impl.ParseResult)5 JSONArray (com.alibaba.fastjson.JSONArray)3 JSONObject (com.alibaba.fastjson.JSONObject)3 NamedNodeMap (org.w3c.dom.NamedNodeMap)3 Node (org.w3c.dom.Node)3 NodeList (org.w3c.dom.NodeList)3 Maps (com.google.common.collect.Maps)2 SelectableServer (com.qlangtech.tis.coredefine.module.control.SelectableServer)2 com.qlangtech.tis.manage.common (com.qlangtech.tis.manage.common)2 ReflectSchemaFieldType (com.qlangtech.tis.plugin.ds.ReflectSchemaFieldType)2 ISchemaField (com.qlangtech.tis.solrdao.ISchemaField)2 WorkFlowCriteria (com.qlangtech.tis.workflow.pojo.WorkFlowCriteria)2 Collectors (java.util.stream.Collectors)2 Context (com.alibaba.citrus.turbine.Context)1 JSON (com.alibaba.fastjson.JSON)1 JSONException (com.alibaba.fastjson.JSONException)1 ActionProxy (com.opensymphony.xwork2.ActionProxy)1 BasicActionTestCase (com.qlangtech.tis.BasicActionTestCase)1 TIS (com.qlangtech.tis.TIS)1