Exemplo n.º 1
0
 /**
  * Retrieve a sibling by sibling number.
  * @param  integer $i - Sibling number.
  * @param  integer $r - R-Value. Wait until this many partitions
  * have responded before returning to client.
  * @return Object.
  */
 public function getSibling($i, $r = NULL)
 {
     # Use defaults if not specified.
     $r = $this->bucket->getR($r);
     # Run the request...
     $vtag = $this->siblings[$i];
     $params = array('r' => $r, 'vtag' => $vtag);
     $url = Utils::buildRestPath($this->client, $this->bucket, $this->key, NULL, $params);
     $response = Utils::httpRequest('GET', $url);
     # Respond with a new object...
     $obj = new Object($this->client, $this->bucket, $this->key);
     $obj->jsonize = $this->jsonize;
     $obj->populate($response, array(200));
     return $obj;
 }
Exemplo n.º 2
0
 /**
  * Search a secondary index
  * @author Eric Stevens <*****@*****.**>
  * @param string $indexName - The name of the index to search
  * @param string $indexType - The type of index ('int' or 'bin')
  * @param string|int $startOrExact
  * @param string|int optional $end
  * @param bool $dedupe - whether to eliminate duplicate entries if any
  * @return array of Links
  */
 public function indexSearch($indexName, $indexType, $startOrExact, $end = NULL, $dedupe = false)
 {
     $url = Utils::buildIndexPath($this->client, $this, "{$indexName}_{$indexType}", $startOrExact, $end, NULL);
     $response = Utils::httpRequest('GET', $url);
     $obj = new Object($this->client, $this, NULL);
     $obj->populate($response, array(200));
     if (!$obj->exists()) {
         throw \Exception("Error searching index.");
     }
     $data = $obj->getData();
     $keys = array_map("urldecode", $data["keys"]);
     $seenKeys = array();
     foreach ($keys as $id => &$key) {
         if ($dedupe) {
             if (isset($seenKeys[$key])) {
                 unset($keys[$id]);
                 continue;
             }
             $seenKeys[$key] = true;
         }
         $key = new Link($this->name, $key);
         $key->client = $this->client;
     }
     return $keys;
 }