コード例 #1
0
ファイル: Setup.php プロジェクト: nickel715/phorkie
 public function reset()
 {
     $r = new \HTTP_Request2($this->searchInstance, \HTTP_Request2::METHOD_DELETE);
     $r->send();
     $r = new Database_Adapter_Elasticsearch_HTTPRequest($this->searchInstance, \HTTP_Request2::METHOD_PUT);
     $r->send();
     //create mapping
     //mapping for repositories
     $r = new Database_Adapter_Elasticsearch_HTTPRequest($this->searchInstance . 'repo/_mapping', \HTTP_Request2::METHOD_PUT);
     $r->setBody(json_encode((object) array('repo' => (object) array('_timestamp' => (object) array('enabled' => true, 'path' => 'tstamp'), 'properties' => (object) array('id' => (object) array('type' => 'long'), 'description' => (object) array('type' => 'string', 'boost' => 2.0), 'crdate' => (object) array('type' => 'date'), 'modate' => (object) array('type' => 'date'), 'tstamp' => (object) array('type' => 'date'))))));
     $r->send();
     //mapping for files
     $r = new Database_Adapter_Elasticsearch_HTTPRequest($this->searchInstance . 'file/_mapping', \HTTP_Request2::METHOD_PUT);
     $r->setBody(json_encode((object) array('file' => (object) array('_parent' => (object) array('type' => 'repo'), 'properties' => (object) array('name' => (object) array('type' => 'string', 'boost' => 1.5), 'extension' => (object) array('type' => 'string', 'boost' => 1.0), 'content' => (object) array('type' => 'string', 'boost' => 0.8))))));
     $r->send();
 }
コード例 #2
0
ファイル: Search.php プロジェクト: nickel715/phorkie
 /**
  * Search for a given term and return repositories that contain it
  * in their description, file names or file content
  *
  * @param string  $term    Search term
  * @param integer $page    Page of search results, starting with 0
  * @param integer $perPage Number of results per page
  *
  * @return Search_Result Search result object
  */
 public function search($term, $page = 0, $perPage = 10)
 {
     $r = new Database_Adapter_Elasticsearch_HTTPRequest($this->searchInstance . 'repo/_search', \HTTP_Request2::METHOD_GET);
     $r->setBody(json_encode((object) array('from' => $page * $perPage, 'size' => $perPage, 'query' => (object) array('bool' => (object) array('should' => array((object) array('query_string' => (object) array('query' => $term, 'default_operator' => 'AND')), (object) array('has_child' => (object) array('type' => 'file', 'query' => (object) array('query_string' => (object) array('query' => $term, 'default_operator' => 'AND'))))))))));
     $httpRes = $r->send();
     $jRes = json_decode($httpRes->getBody());
     if (isset($jRes->error)) {
         throw new Exception('Search exception: ' . $jRes->error, $jRes->status);
     }
     $sres = new Search_Result();
     $sres->results = $jRes->hits->total;
     $sres->page = $page;
     $sres->perPage = $perPage;
     foreach ($jRes->hits->hits as $hit) {
         $r = new Repository();
         //FIXME: error handling. what about deleted repos?
         $r->loadById($hit->_source->id);
         $sres->repos[] = $r;
     }
     return $sres;
 }
コード例 #3
0
ファイル: search.php プロジェクト: nickel715/phorkie
<?php

//search
namespace phorkie;

require_once __DIR__ . '/../src/phorkie/autoload.php';
require_once __DIR__ . '/../data/config.default.php';
if (file_exists(__DIR__ . '/../data/config.php')) {
    require_once __DIR__ . '/../data/config.php';
}
if ($GLOBALS['phorkie']['cfg']['setupcheck']) {
    SetupCheck::run();
}
$r = new Database_Adapter_Elasticsearch_HTTPRequest($GLOBALS['phorkie']['cfg']['elasticsearch'] . 'repo/_search', \HTTP_Request2::METHOD_GET);
$r->setBody(json_encode((object) array('from' => 0, 'size' => 2, 'query' => (object) array('bool' => (object) array('should' => array((object) array('query_string' => (object) array('query' => 'test')), (object) array('has_child' => (object) array('type' => 'file', 'query' => (object) array('query_string' => (object) array('query' => 'test'))))))))));
$res = $r->send();
echo $res->getBody() . "\n";
コード例 #4
0
ファイル: Indexer.php プロジェクト: nickel715/phorkie
 protected function deleteRepoFiles(Repository $repo)
 {
     //delete files of that repository
     $r = new Database_Adapter_Elasticsearch_HTTPRequest($this->searchInstance . 'file/_query' . '?q=_parent:' . $repo->id, \HTTP_Request2::METHOD_DELETE);
     $r->send();
 }