Esempio n. 1
0
 /**
  * Get the value of a header.
  *
  * @param   string  $name  The name of a header
  * @return  string  The value of the header. If it does not exist, returns `null'.
  * @access  public
  */
 function head($name)
 {
     ESTRAIERPURE_DEBUG && EstraierPure_Utility::check_types(array($name, 'string'));
     return isset($this->heads[$name]) ? $this->heads[$name] : null;
 }
Esempio n. 2
0
 /**
  * Search for documents corresponding a condition.
  *
  * @param   object  $cond   EstraierPure_Condition
  *                          which is a condition object.
  * @param   int     $depth  The depth of meta search.
  * @return  object  EstraierPure_NodeResult
  *                  A node result object.
  *                  On error, returns `null'.
  * @access  public
  */
 function &search(&$cond, $depth)
 {
     ESTRAIERPURE_DEBUG && EstraierPure_Utility::check_types(array($cond, 'object', 'EstraierPure_Condition'), array($depth, 'integer'));
     $this->status = -1;
     if (!$this->url) {
         $null = null;
         return $null;
     }
     $turl = $this->url . '/search';
     $reqheads = array('content-type' => 'application/x-www-form-urlencoded');
     if ($this->auth) {
         $reqheads['authorization'] = 'Basic ' . base64_encode($this->auth);
     }
     $reqbody = EstraierPure_Utility::cond_to_query($cond, $depth, $this->wwidth, $this->hwidth, $this->awidth);
     $res =& EstraierPure_Utility::shuttle_url($turl, $this->pxhost, $this->pxport, $this->timeout, $reqheads, $reqbody);
     if (!$res) {
         return null;
     }
     $this->status = $res->status();
     if ($res->is_error()) {
         return null;
     }
     $lines = explode("\n", $res->body());
     if (count($lines) == 0) {
         return null;
     }
     $docs = array();
     $hints = array();
     $border = $lines[0];
     $isend = false;
     $lnum = 1;
     $llen = count($lines);
     $blen = strlen($border);
     while ($lnum < $llen) {
         $line = $lines[$lnum];
         $lnum++;
         if (strlen($line) >= $blen && strpos($line, $border) === 0) {
             if (substr($line, $blen) == ':END') {
                 $isend = true;
             }
             break;
         }
         if (strpos($line, "\t")) {
             list($key, $value) = explode("\t", $line, 2);
             $hints[$key] = $value;
         }
     }
     $snum = $lnum;
     while (!$isend && $lnum < $llen) {
         $line = $lines[$lnum];
         $lnum++;
         if (strlen($line) >= $blen && strpos($line, $border) === 0) {
             if ($lnum > $snum) {
                 $rdattrs = array();
                 $sb = '';
                 $rdvector = '';
                 $rlnum = $snum;
                 while ($rlnum < $lnum - 1) {
                     $rdline = trim($lines[$rlnum]);
                     $rlnum++;
                     if (strlen($rdline) == 0) {
                         break;
                     }
                     if (substr($rdline, 0, 1) == '%') {
                         $lidx = strpos($rdline, "\t");
                         if (strpos($rdline, '%VECTOR') === 0 && $lidx) {
                             $rdvector = substr($rdline, $lidx + 1);
                         }
                     } else {
                         if (strpos($rdline, '=')) {
                             list($key, $value) = explode('=', $rdline, 2);
                             $rdattrs[$key] = $value;
                         }
                     }
                 }
                 while ($rlnum < $lnum - 1) {
                     $rdline = $lines[$rlnum];
                     $rlnum++;
                     $sb .= $rdline . "\n";
                 }
                 $rduri = $rdattrs['@uri'];
                 $rdsnippet = $sb;
                 if ($rduri) {
                     $docs[] =& new EstraierPure_ResultDocument($rduri, $rdattrs, $rdsnippet, $rdvector);
                 }
             }
             $snum = $lnum;
             if (substr($line, $blen) == ':END') {
                 $isend = true;
             }
         }
     }
     if (!$isend) {
         $null = null;
         return $null;
     }
     $result =& new EstraierPure_NodeResult($docs, $hints);
     return $result;
 }