You are viewing a plain text version of this content. The canonical link for it is here.
Posted to xindice-users@xml.apache.org by "webhiker@tiscali.fr" <we...@tiscali.fr> on 2003/12/04 18:56:17 UTC
How to add indexes programatically?
Does anyone have a code snippet showing how I can programmatically add
some indexing, without going through the command-line client?
I didn't see any docs on how to do this, and the javadocs are pretty
spartan.
Many thanks.
WH
Re: How to add indexes programatically?
Posted by Upayavira <uv...@upaya.co.uk>.
webhiker@tiscali.fr wrote:
> Does anyone have a code snippet showing how I can programmatically add
> some indexing, without going through the command-line client?
> I didn't see any docs on how to do this, and the javadocs are pretty
> spartan.
Look at the code for the org.apache.xindice.tools.XMLTools class, and
the config/commands.xml file. Examine these, and from that code you
should be able to work out a way that you can programmatically control
XIndice.
Not necessarily the proper way, but it would work.
Regards, Upayavira
Re: How to add indexes programatically?
Posted by "webhiker@tiscali.fr" <we...@tiscali.fr>.
Thanks all for your input.
Here's my completed method, using Reflection so I can compile against
other xmldb databases..
I'm getting a strange exception trace in Xindice 1.0, pasted below - I'd
appreciate any ideas on why I'm getting this...
/**
* Xindice only method for adding indexes to a Collection.
* Pattern uses the following format :
* Pattern Description
* ===========
====================================================
* elem The value of the named element
* elem@attr The value of the attribute for the named element
* * The value for all elements
* *@attr The value of the named attribute for all elements
* elem@* The value of all attributes for the named element
* *@* 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);
}
catch (Throwable t) {
t.printStackTrace();
}
}
Here's my exception trace in the Xindince server, called with parameters
name="ArbitraryName" and pattern="*" :
java.lang.NullPointerException
at org.apache.xindice.core.filer.BTree.findValue(BTree.java:213)
at org.apache.xindice.core.filer.BTree.findBTreeRoot(BTree.java:292)
at
org.apache.xindice.core.indexer.ValueIndexer.add(ValueIndexer.java:345)
at
org.apache.xindice.core.indexer.IndexManager$SAXHandler.processEntry(IndexManager.java:500)
at
org.apache.xindice.core.indexer.IndexManager$SAXHandler.endElement(IndexManager.java:538)
at
org.apache.xindice.xml.sax.SAXEventGenerator.processContainer(SAXEventGenerator.java:330)
at
org.apache.xindice.xml.sax.SAXEventGenerator.processContainer(SAXEventGenerator.java:269)
at
org.apache.xindice.xml.sax.SAXEventGenerator.processContainer(SAXEventGenerator.java:269)
at
org.apache.xindice.xml.sax.SAXEventGenerator.processContainer(SAXEventGenerator.java:269)
at
org.apache.xindice.xml.sax.SAXEventGenerator.start(SAXEventGenerator.java:342)
at
org.apache.xindice.core.indexer.IndexManager$SAXHandler.<init>(IndexManager.java:462)
at
org.apache.xindice.core.indexer.IndexManager$SAXHandler.<init>(IndexManager.java:478)
at
org.apache.xindice.core.indexer.IndexManager.addDocument(IndexManager.java:392)
at
org.apache.xindice.core.Collection.putDocument(Collection.java:627)
at
org.apache.xindice.core.Collection.insertDocument(Collection.java:659)
at
org.apache.xindice.client.corba.CollectionServant.insertDocument(CollectionServant.java:317)
at
org.apache.xindice.client.corba.db.CollectionPOA._invoke(CollectionPOA.java:181)
at org.openorb.adapter.poa.POA.dispatch(POA.java:975)
at
org.openorb.net.AbstractServerRequest.dispatch(AbstractServerRequest.java:750)
at
org.openorb.net.ServerManagerImpl.serve_request(ServerManagerImpl.java:1467)
at
org.openorb.net.ServerManagerImpl.thread_pool_main(ServerManagerImpl.java:1410)
at
org.openorb.net.ServerManagerImpl.access$200(ServerManagerImpl.java:77)
at
org.openorb.net.ServerManagerImpl$PoolThread.run(ServerManagerImpl.java:1557)
DEBUG> Index Creation: batchIndex
DEBUG> Index Complete: batchIndex
DEBUG> Populated Indexes: 187ms
Re: How to add indexes programatically?
Posted by Mario Cormier <mc...@miranda.com>.
I used something like this to list/create indexes:
CollectionManager colman = (CollectionManager)
myCollection.getService("CollectionManager", "1.0");
String[] idx = colman.listIndexers();
if (idx.length < 1) {
log.info("initializeXMLDB - Creating indexer");
String document = "<index
class='org.apache.xindice.core.indexer.ValueIndexer' name='star_at_star'
pattern='*@*' />";
// optional: type='' pagesize='' maxkeysize=''
colman.createIndexer(DOMParser.toDocument(document));
}
if (log.isDebugEnabled()) {
log.debug("initializeXMLDB - Indexes:\n");
for (int i = 0; i < idx.length; i++) {
log.debug("initializeXMLDB - " + i + " - " + idx[i]);
}
log.debug("initializeXMLDB - Total Indexes: " + idx.length);
}
Hope this helps!
Mario
webhiker@tiscali.fr wrote:
> Does anyone have a code snippet showing how I can programmatically add
> some indexing, without going through the command-line client?
> I didn't see any docs on how to do this, and the javadocs are pretty
> spartan.
>
> Many thanks.
> WH