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
 /**
  * Serialize a condition object into a query string.
  *
  * @param   object  $cond   Services_HyperEstraier_Condition
  *                          which is a condition object.
  * @param   int     $depth  Depth of meta search
  * @param   int     $wwidth Whole width of a snippet
  * @param   int     $hwidth Width of strings picked up from the beginning of the text
  * @param   int     $awidth Width of strings picked up around each highlighted word
  * @return  string  The serialized string.
  * @access  public
  * @static
  * @ignore
  */
 public static function conditionToQuery(Services_HyperEstraier_Condition $cond, $depth, $wwidth, $hwidth, $awidth)
 {
     $query = '';
     if ($phrase = $cond->getPhrase()) {
         $query .= '&phrase=' . urlencode($phrase);
     }
     if ($attrs = $cond->getAttributes()) {
         $i = 0;
         foreach ($attrs as $attr) {
             $query .= '&attr' . strval(++$i) . '=' . urlencode($attr);
         }
     }
     if (strlen($order = $cond->getOrder()) > 0) {
         $query .= '&order=' . urlencode($order);
     }
     $query .= '&max=' . strval(($max = $cond->getMax()) >= 0 ? $max : 1 << 30);
     if (($options = $cond->getOptions()) > 0) {
         $query .= '&options=' . strval($options);
     }
     $query .= '&auxiliary=' . strval($cond->getAuxiliary());
     if (strlen($distinct = $cond->getDistinct()) > 0) {
         $query .= '&distinct=' . urlencode($distinct);
     }
     if ($depth > 0) {
         $query .= '&depth=' . strval($depth);
     }
     $query .= '&wwidth=' . strval($wwidth);
     $query .= '&hwidth=' . strval($hwidth);
     $query .= '&awidth=' . strval($awidth);
     $query .= '&skip=' . strval($cond->getSkip());
     $query .= '&mask=' . strval($cond->getMask());
     return substr($query, 1);
 }
Exemplo n.º 3
0
 /**
  * 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);
 }