Testing Xindice


"); // Create the Xindice access object $xi=new Xindice("$server",$port); if(!$xi) { die("Cannot create Xindice object, check servername and port
"); } $xi->setXmlRpcDebug(0); // Create a collection "pepe" under db $xi->createCollection($base,"pepe"); // Insert a sample document there $a_doc=' Foo 10 Goo 83 '; $xi->insertDocument("$base/pepe","cosa",$a_doc); // List collections under base, should be an Array with "system" and "pepe" $cols=$xi->listCollections($base); print(""); foreach($cols as $col) { print(""); } print("
Collections under $base:
Collection$col

"); // List number of documents under base/pepe should be 1 (the inserted doc) $tot=$xi->getDocumentCount($base."/pepe"); print(""); if($tot==1) { print("
Documents in $base/pepe: $tot
Test passed ok
"); } print("
"); // List the documents under base/pepe should be "cosa" $docs=$xi->listDocuments($base."/pepe"); print(""); foreach($docs as $doc) { print("
Documents in $base/pepe: $tot
Document$doc
"); } print("
"); // Retrieve the "cosa" document $cosa=$xi->getDocument($base."/pepe","cosa"); print(""); print("
Document cosa:
"); print("
"); // Remove the document $xi->removeDocument($base."/pepe","cosa"); // List number of documents under base/pepe should be 0 $tot=$xi->getDocumentCount($base."/pepe"); print(""); if($tot==0) { print("
Documents in $base/pepe after removal: $tot
Test passed ok
"); } print("
"); // Re-insert the document $xi->insertDocument($base."/pepe","cosa",$cosa); // Make an Xpath query on the collection $query=$xi->queryCollection($base."/pepe","XPath","//name"); print(""); print("
Query result (queryCollection):
"); print("
"); // And the document $query=$xi->queryDocument($base."/pepe","XPath","//name","cosa"); print(""); print("
Query result (queryDocument):
"); print("
"); // An Xupdate modification $modification=' Pirincho2 '; $query=$xi->queryDocument($base."/pepe","XUpdate","$modification","cosa"); // Retrieve the updated document $cosa=$xi->getDocument("/db/pepe","cosa"); print(""); print("
Updated document:
"); print("
"); // Drop the test collection //$xi->dropCollection($base."/pepe"); ?>