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);
}
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);
}
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);
}
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());
}
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;
}
Aggregations