Detailed description and usage:
include_once("class_xindice.php");
// Create the Xindice access object
$xi=new Xindice("$server",$port); //Default port is 4080
if(!$xi) {
die("Cannot create Xindice object, check servername and port ");
}
$xi->setXmlRpcDebug(0);
Once the class is instantiated use the object to call Xindice's RPC methods, check the following documentation
for a complete listing of methods that can be called and what they do. The test.php script in this distribution
checks the correct working of the class and the Xindice RPC Api.
Documentation
Classes
class_xindice
Extends: None
Description: This class implements the Xindice 1.0 XML-RPC API as class methods allowing PHP scripts to use an Xindice database server
Method Summary |
void |
Xindice(string $server_uri, int $server_port)
Constructor |
string |
getError(string $server_uri, int $server_port)
Returns the error message when a method fails |
void |
setXmlRpcDebug(boolean $debug)
Sets the debug method of the XML-RPC library |
boolean |
createCollection(string $base, string $collectionName)
Creates a collection from a base collection |
array |
listCollections(string $collection)
Lists collections under a parent collection |
int |
getDocumentCount(string $collectionPath)
Returns the number of documents in a collection |
boolean |
dropCollection(string $collectionPath)
Drops a collection |
boolean |
insertDocument(string $collection, string $id, string $content)
Inserts a new document in a collection |
boolean |
setDocument(string $collection, string $id, string $content)
Updates/sets a document |
string |
getDocument(string $collection, string $id)
Retrieves a document from the database |
array |
listDocuments(string $collection)
Lists the documents under a collection |
boolean |
removeDocument(string $collection, string $id)
Removes a document from a collection |
boolean |
createIndexer(string $collection, string $indexName, string $pattern)
Creates an index |
boolean |
dropIndexer(string $collection, string $indexName)
Drops an index |
Array |
listIndexers(string $collection)
List indexes created on a collection |
string |
queryDocument(string $collection, string $type, string $query, string $id)
Queries a document |
string |
queryCollection(string $collection, string $type, string $query)
Queries a collection |
Xindice
void Xindice(string $server_uri, int $server_port)
- Constructor, must receive the URI of the Xindice server an optionally the port that the server uses (default=4080)
-
- Parameters:
-
$server_uri - URI of the Xindice server, use "localhost" if local.
$server_port - Optional parameter indicating the Xindice server's port, defaulted to 4080 if not present.
- Returns:
- Nothing
- Throws:
None
getError
string getError(string $server_uri, int $server_port)
- If a method fails returning false you can check the value returned from this method for a description of an error.
-
- Parameters:
-
- Returns:
- Error message
- Throws:
None
setXmlRpcDebug
void setXmlRpcDebug(boolean $debug)
- This class uses an XML-RPC library, if something goes wrong you can turn the XML-RPC debug of the library on using this method.
-
- Parameters:
-
$debug - Set it ti true to turn debug mode on or false tu turn it off
- Returns:
- Nothing
- Throws:
None
createCollection
boolean createCollection(string $base, string $collectionName)
- Creates a collection from a base collection
-
- Parameters:
-
$base - Name of the base collection where the new collection will be created
$collectionName - Name of the new creation to be created
- Returns:
- Throws:
None
listCollections
array listCollections(string $collection)
- This method returns an array of strings with the names of collections under the parent collection passed as argument only child collections are returned not all the descendant collections
-
- Parameters:
-
$collection - Name of the parent collection to be used
- Returns:
- An array with the name of the collections under the collection passed as argument
- Throws:
None
getDocumentCount
int getDocumentCount(string $collectionPath)
- Returns the number of documents present in the collection passed as argument
-
- Parameters:
-
$collectionPath - Collection name
- Returns:
- The number of documents held by the collection
- Throws:
None
dropCollection
boolean dropCollection(string $collectionPath)
- Drops a collection all documents and subcollections under the collection are removed as well
-
- Parameters:
-
$collectionPath - Path to the collection to be removed
- Returns:
- Throws:
None
insertDocument
boolean insertDocument(string $collection, string $id, string $content)
- Inserts a new document in a collection
-
- Parameters:
-
$collection - Name of the collection where the document will be inserted
$id - A string identifying the document inside the collection $content - The XML document to be inserted
- Returns:
- Throws:
None
setDocument
boolean setDocument(string $collection, string $id, string $content)
- Updates/sets a document
-
- Parameters:
-
$collection - Name of the collection where the document resides
$id - Id of the document to be updated $content - New XML content to be set
- Returns:
- Throws:
None
getDocument
string getDocument(string $collection, string $id)
- Retrieves a document from the database
-
- Parameters:
-
$collection - Collection name
$id - Document id
- Returns:
- The XML document or false if it not found
- Throws:
None
listDocuments
array listDocuments(string $collection)
- Returns an array of document names blonging to the given collection
-
- Parameters:
-
$collection - Name of the collection
- Returns:
- An array of strings containing the documents' names
- Throws:
None
removeDocument
boolean removeDocument(string $collection, string $id)
- Removes a document from a collection
-
- Parameters:
-
$collection - Name of the collection
$id - Id of the document to be removed
- Returns:
- Throws:
None
createIndexer
boolean createIndexer(string $collection, string $indexName, string $pattern)
- This method creates an index on a collection given a pattern
-
- Parameters:
-
$collection - Name of the collection where the index will be created
$indexName - Name of the index that will be created $pattern - Pattern for the index
- Returns:
- Throws:
None
dropIndexer
boolean dropIndexer(string $collection, string $indexName)
- Drops an index created for a collection
-
- Parameters:
-
$collection - Name of the collection
$indexName - Name of the index to be dropped from the collection
- Returns:
- Throws:
None
listIndexers
Array listIndexers(string $collection)
- List indexes created on a collection
-
- Parameters:
-
$collection - Name of the collection
- Returns:
- An array of indexNames existing for the collection
- Throws:
None
queryDocument
string queryDocument(string $collection, string $type, string $query, string $id)
- This method is used to execute a query on a document from some collection, it can execute Xpath or XUpdate queries.
-
- Parameters:
-
$collection - Name of the collection where the document belongs
$type - Name of the type of query (XPath or XUpdate) $query - Query to be executed $id - Id of the document to be queried
- Returns:
- The result of the query
- Throws:
None
queryCollection
string queryCollection(string $collection, string $type, string $query)
- This method is used to query all the documents in a collection
-
- Parameters:
-
$collection - Name of the collection
$type - Type of query (XPath or XUpdate) $query - Query to be executed on the collection
- Returns:
- Query result
- Throws:
None
|