<?php require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . 'common.php'; // create and configure the node connecton object $node = new Services_HyperEstraier_Node(); $node->setUrl($uri); // create a search condition object $cond = new Services_HyperEstraier_Condition(); $cond->setPhrase('water AND mind'); $cond->setMax(10); $cond->setSkip(0); // get the result of search $nres = $node->search($cond, 0); if ($nres) { if ($nres->docNum() == 0) { fprintf(STDOUT, "%s: not found.\n", $cond->getPhrase()); } else { foreach ($nres as $rdoc) { // display attributes if (($value = $rdoc->getAttribute('@uri')) !== null) { fprintf(STDOUT, "URI: %s\n", $value); } if (($value = $rdoc->getAttribute('@title')) !== null) { fprintf(STDOUT, "Title: %s\n", $value); } // display the snippet text (with property overloading) fprintf(STDOUT, "%s", $rdoc->snippet); } } } else { fprintf(STDERR, "error: %d\n", $node->status);
/** * Search for documents corresponding a phrase. * * @param string $url The url of a node server. * Also includes the username and the password. * @param string $phrase A search phrase. * @param int $limit The maximum number of retrieval. * By default, the number of retrieval is not limited. * @param int $offset The number of documents to be skipped. * By default, it is 0. * @return object Services_HyperEstraier_NodeResult * A node result object. * On error, returns `null'. * @throws InvalidArgumentException * @access public * @static */ public static function search($url, $phrase, $limit = -1, $offset = 0) { $node = self::_getNode($url); $cond = new Services_HyperEstraier_Condition(); $cond->setPhrase($phrase); $cond->setMax($limit); $cond->setSkip($offset); return $node->search($cond, 0); }