自定义索引行为
您可以修改与 Windchill 业务对象相关联的搜索引擎索引信息。
配置 DefaultIndexObjectBuilder
为以下包含签名的方法提供实现:protected void setAdditionalAttributes(EPMDocument indexable, TypeInstance ti, WCIndexingObject indexingObject, WTCollection sharedMapCollection) throws WTException
要使用自定义的 DefaultIndexObjectBuilder 类,必须更新 service.properties 文件以反映此更改。
以下为默认条目:
# #####################################################
# The wt.index.builder.IndexObjectBuilder service.
# ###########################################################
wt.services/svc/default/wt.index.builder.IndexObjectBuilder/
null/wt.index.Indexable/0=wt.index.builder.DefaultIndexObjectBuilder
/duplicate
在本示例中,假设您有一个名为 DemoIndexObjectBuilder 的自定义 DefaultIndexObjectBuilder,且想要将其用于索引。如果要覆盖默认值 DefaultIndexObjectBuilder,必须将以下行添加到 service.properties:wt.services/svc/default/wt.index.builder.IndexObjectBuilder/null/wt.epm.EPMDocument/0=wt.index.builder.DemoIndexObjectBuilder/duplicate
setAdditionalAttributes
您可以覆盖 custom_ setAdditionalAttributes(EPMDocument indexable, TypeInstance ti, WCIndexingObject indexingObject, WTCollection sharedMapCollection) 方法并将您的特定代码添加到此方法中。
示例
import wt.epm.EPMDocument;
import wt.fc.collections.WTCollection;
import wt.index.IndexAttributeInfo;
import wt.index.WCIndexingObject;
import wt.util.WTException;
import com.ptc.core.meta.type.common.TypeInstance;
/**
* Demo IndexObjectBuilder implementation for EPMDocument object type.
*/
public class DemoIndexObjectBuilder extends
DefaultIndexObjectBuilder<EPMDocument> {
/* Override setAdditionalAttributes method to set additional attributes in
* IndexingObject so that it gets indexed to SOLR and is searchable
* The super class already has some implementation, so have to call
* super.setAdditionalAttributes method explicitly Instead we can have a
* custom method that can be overridden and keep it's implementation
* empty in DefaultIndexObjectBuilder
* (non-Javadoc)
* @see wt.index.builder.DefaultIndexObjectBuilder#setAdditionalAttributes
* (wt.index.Indexable, com.ptc.core.meta.type.common.TypeInstance,
* wt.index.WCIndexingObject, wt.fc.collections.WTCollection)
*/
@Override
protected void setAdditionalAttributes(EPMDocument indexable, TypeInstance ti,
WCIndexingObject indexingObject, WTCollection sharedMapCollection)
throws WTException {
//call the setAdditionalAttributes method of super class to keep the
//existing implementation intact
super.setAdditionalAttributes(indexable, ti, indexingObject, sharedMapCollection);
//Get the additional values to be indexed from TypeInstance or any
//other custom implementation
String demoVal = "SOME_VALUE";
//Get the custom for which user wants solr field. Like SOME_ATTRIBUTE
IndexAttributeInfo attributeInfo = getAttributeInfo
("SOME_ATTRIBUTE", demoVal, false);
//If the attribute value needs to be indexed as a separate field in SOLR,
//then add it to unmappedAttInfo list in IndexingObject
indexingObject.addToUnmappedAttInfo(attributeInfo);
//If the attribute value needs to be searchable via keyword, then append the
//value to the metadata field whose content is searchable through keyword
indexingObject.appendMetadataField(demoVal);
}
}