Exemplo n.º 1
0
<?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);
Exemplo n.º 2
0
<?php

require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . 'common.php';
// create and configure the node connecton object
$node = new Services_HyperEstraier_Node();
$node->setUrl($uri);
$node->setAuth($user, $pass);
// remove the document specified by URI.
if (!$node->outDocumentByUri('http://estraier.example.com/example.txt')) {
    fprintf(STDERR, "error: %d\n", $node->status);
    if (Services_HyperEstraier_Error::hasErrors()) {
        fputs(STDERR, print_r(Services_HyperEstraier_Error::getErrors(), true));
    }
} else {
    fputs(STDOUT, "success.\n");
}
Exemplo n.º 3
0
<?php

require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . 'common.php';
// create and configure the node connecton object
$node = new Services_HyperEstraier_Node();
$node->setUrl($uri);
$node->setAuth($user, $pass);
// create a document object
$doc = new Services_HyperEstraier_Document();
// add attributes to the document object
$doc->addAttribute('@uri', 'http://estraier.example.com/example.txt');
$doc->addAttribute('@title', 'Bridge Over The Troubled Water');
// add the body text to the document object
$doc->addText('Like a bridge over the troubled water,');
$doc->addText('I will ease your mind.');
// register the document object to the node
if (!$node->putDocument($doc)) {
    fprintf(STDERR, "error: %d\n", $node->status);
    if (Services_HyperEstraier_Error::hasErrors()) {
        fputs(STDERR, print_r(Services_HyperEstraier_Error::getErrors(), true));
    }
} else {
    fputs(STDOUT, "success.\n");
}
Exemplo n.º 4
0
 /**
  * Get a node object.
  *
  * @param   string  $url    The url of a node server.
  *                          Also includes the username and the password.
  * @return  object  Services_HyperEstraier_Node
  * @throws  InvalidArgumentException
  * @access  private
  * @static
  * @ignore
  */
 private static function _getNode($url)
 {
     static $node = null;
     static $checksum = '';
     // parse the url
     if (!is_string($url)) {
         throw new InvalidArgumentException(sprintf('Argument#2 should be a kind of integer or string, %s given.', gettype($id)));
     }
     if (!($purl = @parse_url($url)) || !isset($purl['scheme']) || strcasecmp($purl['scheme'], 'http') != 0 || !isset($purl['host']) || !isset($purl['path']) || (isset($purl['user']) xor isset($purl['pass']))) {
         throw new InvalidArgumentException('Invalid URL given.');
     }
     // check if the node object is cached
     $newchecksum = md5($url);
     if ($checksum != $newchecksum) {
         $node = new Services_HyperEstraier_Node();
         $nurl = 'http://' . $purl['host'];
         if (isset($purl['port'])) {
             $nurl .= ':' . $purl['port'];
         }
         $nurl .= $purl['path'];
         $node->setUrl($nurl);
         if (isset($purl['user']) && isset($purl['pass'])) {
             $node->setAuth($purl['user'], $purl['pass']);
         }
         $checksum = $newchecksum;
     }
     return $node;
 }