/**
* Xindice only method for adding indexes to a Collection.
* Pattern uses the following format :
* Pattern Description
* =========== ====================================================
* elem The value of the named element
* [EMAIL PROTECTED] The value of the attribute for the named element
* * The value for all elements
* [EMAIL PROTECTED] The value of the named attribute for all elements
* [EMAIL PROTECTED] The value of all attributes for the named element
* [EMAIL PROTECTED] The value of all attributes for all elements
*/
public void addIndex(Collection collection, String name, String pattern)
throws XMLDBException,
javax.xml.parsers.ParserConfigurationException {
Service collectionManager; // should be of type org.apache.xindice.client.xmldb.services.CollectionManager
collectionManager = collection.getService("CollectionManager", "1.0");
logger.info("Creating indexer");
try {
DocumentBuilder documentBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
org.w3c.dom.Document document = documentBuilder.newDocument();
org.w3c.dom.Element element = document.createElement("index");
document.appendChild(element);
element.setAttribute("class","org.apache.xindice.core.indexer.ValueIndexer");
element.setAttribute("name",name);
element.setAttribute("pattern",pattern);
//element.setAttribute("type",""); // optional
//element.setAttribute("pagesize",""); // optional
//element.setAttribute("maxkeysize","");// optional
Method createIndexerMethod = collectionManager.getClass().getDeclaredMethod("createIndexer",
new Class[]{org.w3c.dom.Document.class});
Object args[] = new Object[]{document};
createIndexerMethod.invoke(collectionManager,args);
// logger.debug("Listing indexes:");
// String[] idx = collectionManager.listIndexers();
// for (int i = 0; i < idx.length; i++) {
// logger.debug("initializeXMLDB - " + i + " - " + idx[i]);
// }
// logger.debug("initializeXMLDB - Total Indexes: " + idx.length);
}
catch (Throwable t) {
t.printStackTrace();
}
}






Reply via email to