X-Git-Url: https://git.cweiske.de/phorkie.git/blobdiff_plain/06524ec25d81c383bc801dee70582a42b348303c..11c020441ee7ddf53fcaec4250c0a408fa18d0be:/scripts/index.php diff --git a/scripts/index.php b/scripts/index.php index 893e3fb..4b529d1 100644 --- a/scripts/index.php +++ b/scripts/index.php @@ -24,84 +24,19 @@ if ($GLOBALS['phorkie']['cfg']['setupcheck']) { SetupCheck::run(); } -//delete all repos -$r = new \HTTP_Request2( - $GLOBALS['phorkie']['cfg']['elasticsearch'] . 'repo/_query', - \HTTP_Request2::METHOD_DELETE -); -$r->setBody( - json_encode( - (object)array( - 'match_all' => (object)array() - ) - ) -); -$r->send(); -$r = new \HTTP_Request2( - $GLOBALS['phorkie']['cfg']['elasticsearch'] . 'file/_query', - \HTTP_Request2::METHOD_DELETE -); -$r->setBody( - json_encode( - (object)array( - 'match_all' => (object)array() - ) - ) -); -$r->send(); -//create mapping -$r = new \HTTP_Request2( - $GLOBALS['phorkie']['cfg']['elasticsearch'] . 'file/_mapping', - \HTTP_Request2::METHOD_PUT -); -$r->setBody( - json_encode( - (object)array( - 'file' => (object)array( - '_parent' => (object)array( - 'type' => 'repo' - ) - ) - ) - ) -); -$r->send(); +$db = new Database(); +$idx = $db->getIndexer(); +//create mapping +echo "Index reset\n"; +$db->getSetup()->reset(); -//FIXME: define schema $rs = new Repositories(); -foreach ($rs->getList(0, 10000) as $repo) { - $r = new \HTTP_Request2( - $GLOBALS['phorkie']['cfg']['elasticsearch'] . 'repo/' . $repo->id, - \HTTP_Request2::METHOD_PUT - ); - $r->setBody( - json_encode( - (object)array( - 'id' => $repo->id, - 'description' => $repo->getDescription(), - ) - ) - ); - $res = $r->send(); - - foreach ($repo->getFiles() as $file) { - $r = new \HTTP_Request2( - $GLOBALS['phorkie']['cfg']['elasticsearch'] . 'file/?parent=' . $repo->id, - \HTTP_Request2::METHOD_POST - ); - $r->setBody( - json_encode( - (object)array( - 'name' => $file->getFilename(), - 'extension' => $file->getExt(), - 'content' => $file->isText() ? $file->getContent() : '', - ) - ) - ); - $r->send(); - } +list($repos, $count) = $rs->getList(0, 10000); +foreach ($repos as $repo) { + echo 'Indexing ' . $repo->id . "\n"; + $idx->addRepo($repo, filectime($repo->gitDir)); } ?>