use of com.qlangtech.tis.plugin.solr.schema.FieldTypeFactory 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.plugin.solr.schema.FieldTypeFactory 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.plugin.solr.schema.FieldTypeFactory in project tis by qlangtech.
the class SchemaAction method updateSchemaXML.
/**
* @param fieldTypes 已经存在的字段类型
* @param schemaForm
* @param document2
* @param modifier
*/
private static void updateSchemaXML(Map<String, SolrType> fieldTypes, ISchemaPluginContext schemaPlugin, ISchema schemaForm, Document document2, final XModifier modifier) {
SolrType type = null;
String fieldTypeRef = null;
FieldTypeFactory fieldTypeFactory = null;
String pluginName = null;
for (ISchemaField field : schemaForm.getSchemaFields()) {
modifySchemaProperty(modifier, field, "type", (fieldTypeRef = parseSolrFieldType(field)));
modifySchemaProperty(modifier, field, "stored", field.isStored());
modifySchemaProperty(modifier, field, "indexed", field.isIndexed());
modifySchemaProperty(modifier, field, "docValues", field.isDocValue());
modifySchemaProperty(modifier, field, "multiValued", field.isMultiValue());
type = fieldTypes.get(fieldTypeRef);
Objects.requireNonNull(type, "fieldName:" + field.getName() + " relevant fieldType can not be null");
if (type.plugin) {
pluginName = type.getPluginName();
fieldTypeFactory = schemaPlugin.findFieldTypeFactory(pluginName);
Objects.requireNonNull(fieldTypeFactory, "pluginName:" + pluginName + " relevant fieldTypeFactory can not be null");
fieldTypeFactory.process(document2, modifier);
}
}
if (StringUtils.isNotBlank(schemaForm.getUniqueKey())) {
modifySchemaProperty("/uniqueKey/text()", schemaForm.getUniqueKey(), modifier);
} else {
modifier.deleteUniqueKey();
}
if (StringUtils.isNotBlank(schemaForm.getSharedKey())) {
modifySchemaProperty("/sharedKey/text()", schemaForm.getSharedKey(), modifier);
} else {
modifier.deleteSharedKey();
}
}
use of com.qlangtech.tis.plugin.solr.schema.FieldTypeFactory in project tis by qlangtech.
the class SchemaAction method parseSchemaResultWithPluginCfg.
public static SchemaResult parseSchemaResultWithPluginCfg(String collection, IMessageHandler msgHandler, Context context, byte[] resContent) throws Exception {
final Map<String, Boolean> pluginTypeAddedMap = Maps.newHashMap();
ISchemaPluginContext schemaPlugin = createSchemaPlugin(collection);
SchemaResult schemaResult = SchemaResult.parseSchemaResult(msgHandler, context, resContent, false, schemaPlugin, (cols, sResult) -> {
boolean pluginTypeAdded;
String identityNameVal = null;
List<FieldTypeFactory> fieldTypeFactories = schemaPlugin.getFieldTypeFactories();
for (FieldTypeFactory plugin : fieldTypeFactories) {
identityNameVal = plugin.identityValue();
if (!(pluginTypeAdded = sResult.containType(identityNameVal))) {
sResult.addFieldType(identityNameVal, SolrFieldsParser.parseFieldType(identityNameVal, identityNameVal, plugin.forStringTokenizer()));
}
pluginTypeAddedMap.put(identityNameVal, pluginTypeAdded);
}
});
schemaResult.content = XModifier.modifySchemaContent(schemaResult.content, (document2, modifier) -> {
// FieldTypeFactory fieldTypeFactory = null;
for (Map.Entry<String, Boolean> entry : pluginTypeAddedMap.entrySet()) {
if (!entry.getValue()) {
// fieldTypeFactory = fieldTypePluginStore.find(entry.getKey());
// Objects.requireNonNull(fieldTypeFactory, "the name:" + entry.getKey() + " relevant fieldTypeFactory can not be null");
// fieldTypeFactory.
modifier.addModify(String.format("/types/fieldType[@name='%s']/@class", entry.getKey()), "plugin:" + entry.getKey());
// precisionStep="0" positionIncrementGap="0"
// modifier.addModify(String.format("/types/fieldType[@name='%s']/@precisionStep", entry.getKey()), "0");
modifier.addModify(String.format("/types/fieldType[@name='%s']/@positionIncrementGap", entry.getKey()), "0");
}
}
});
return schemaResult;
}
Aggregations