use of com.qlangtech.tis.solrdao.impl.ParseResult in project tis by qlangtech.
the class TestSolrFieldParser method testSchemaFields.
public void testSchemaFields() throws Exception {
// SolrFieldsParser solrFieldsParser = new SolrFieldsParser();
try (InputStream reader = this.getClass().getResourceAsStream("schema-sample.txt")) {
assertNotNull(reader);
IIndexMetaData meta = SolrFieldsParser.parse(() -> IOUtils.toByteArray(reader), (typeName) -> {
throw new UnsupportedOperationException();
});
ParseResult parseResult = meta.getSchemaParseResult();
Assert.assertTrue("isValid shall be true", parseResult.isValid());
Assert.assertEquals(20, parseResult.dFields.size());
System.out.println("dFields.size:" + parseResult.dFields.size());
Assert.assertEquals("parseResult.getFieldNameSet() can not be empty", 20, parseResult.getFieldNameSet().size());
System.out.println(parseResult.getFieldNameSet().size());
}
}
use of com.qlangtech.tis.solrdao.impl.ParseResult in project tis by qlangtech.
the class TestSchemaResult method testParseSchemaResultAlreadyContainFieldPlugin.
/**
* 在schema配置文件中已经添加了 <br/>
* <fieldType name="test" class="plugin:test" precisionStep="0" positionIncrementGap="0"/>
* 该类型也要能自动加入到傻瓜模式下,string类型的联动下拉框 <br/>
*
* @throws Exception
*/
public void testParseSchemaResultAlreadyContainFieldPlugin() throws Exception {
IMessageHandler msgHandler = EasyMock.createMock("msgHandler", IMessageHandler.class);
Context context = EasyMock.createMock("context", Context.class);
assertEquals(FieldTypeFactory.class, HeteroEnum.SOLR_FIELD_TYPE.extensionPoint);
IPluginStore<FieldTypeFactory> fieldTypePluginStore = TIS.getPluginStore(collection, FieldTypeFactory.class);
assertNotNull(fieldTypePluginStore);
final String testFieldTypeName = "test";
final List<FieldTypeFactory> plugins = fieldTypePluginStore.getPlugins();
assertTrue(plugins.size() > 0);
FieldTypeFactory fieldType = fieldTypePluginStore.find(testFieldTypeName);
assertNotNull("fieldType can not be null", fieldType);
try (InputStream schema = this.getClass().getResourceAsStream("s4totalpay-schema-already-contain-fieldtype-plugin.xml")) {
EasyMock.replay(msgHandler, context);
SchemaResult schemaResult = SchemaAction.parseSchemaResultWithPluginCfg(collection, msgHandler, context, IOUtils.toByteArray(schema));
Collection<SolrFieldsParser.SolrType> fieldTypes = ((ParseResult) schemaResult.getParseResult()).getFieldTypes();
assertEquals("fieldTypes size", 2, fieldTypes.size());
// String content = (com.alibaba.fastjson.JSON.toJSONString(schemaResult.toJSON()
// , SerializerFeature.DisableCircularReferenceDetect, SerializerFeature.PrettyFormat));
// try (InputStream assertSchemaResultInput = this.getClass().getResourceAsStream("s4totalpay-schema-already-contain-fieldtype-plugin-schema-result.json")) {
// assertNotNull(assertSchemaResultInput);
// FileUtils.write(new File("test.json"), content, TisUTF8.get());
// assertEquals(StringUtils.trim(IOUtils.toString(assertSchemaResultInput, TisUTF8.get())), content);
// }
JsonUtil.assertJSONEqual(this.getClass(), "s4totalpay-schema-already-contain-fieldtype-plugin-schema-result.json", schemaResult.toJSON(), (m, e, a) -> {
assertEquals(m, e, a);
});
}
EasyMock.verify(msgHandler, context);
}
use of com.qlangtech.tis.solrdao.impl.ParseResult in project tis by qlangtech.
the class TestSchemaResult method testParseSchemaResult.
/**
* 模拟用户刚添加fieldtype plugin,则用户第一次家在schema中要自动加入 fieldtype
*
* @throws Exception
*/
public void testParseSchemaResult() throws Exception {
IMessageHandler msgHandler = EasyMock.createMock("msgHandler", IMessageHandler.class);
Context context = EasyMock.createMock("context", Context.class);
assertEquals(FieldTypeFactory.class, HeteroEnum.SOLR_FIELD_TYPE.extensionPoint);
final String collection = "search4totalpay";
IPluginStore<FieldTypeFactory> fieldTypePluginStore = TIS.getPluginStore(collection, FieldTypeFactory.class);
assertNotNull(fieldTypePluginStore);
final String testFieldTypeName = "test";
final List<FieldTypeFactory> plugins = fieldTypePluginStore.getPlugins();
assertTrue(plugins.size() > 0);
FieldTypeFactory fieldType = fieldTypePluginStore.find(testFieldTypeName);
assertNotNull("fieldType can not be null", fieldType);
try (InputStream schema = this.getClass().getResourceAsStream("s4totalpay-schema.xml")) {
EasyMock.replay(msgHandler, context);
SchemaResult schemaResult = SchemaAction.parseSchemaResultWithPluginCfg(collection, msgHandler, context, IOUtils.toByteArray(schema));
Collection<SolrFieldsParser.SolrType> fieldTypes = ((ParseResult) schemaResult.getParseResult()).getFieldTypes();
assertEquals("fieldTypes size", 16, fieldTypes.size());
// String content = (com.alibaba.fastjson.JSON.toJSONString(schemaResult.toJSON()
// , SerializerFeature.DisableCircularReferenceDetect, SerializerFeature.PrettyFormat));
//
// try (InputStream assertSchemaResultInput = this.getClass().getResourceAsStream("assertSchemaResult.json")) {
// assertNotNull(assertSchemaResultInput);
// assertEquals(IOUtils.toString(assertSchemaResultInput, TisUTF8.get()), content);
// }
JsonUtil.assertJSONEqual(this.getClass(), "assertSchemaResult.json", schemaResult.toJSON(), (m, e, a) -> {
assertEquals(m, e, a);
});
}
EasyMock.verify(msgHandler, context);
}
use of com.qlangtech.tis.solrdao.impl.ParseResult 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.impl.ParseResult 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());
}
Aggregations