/** * returns SOLR results: nodeId children * @param [type] $id [description] * @return [type] [description] */ public static function solrGetChildren($id, $fileId = null) { $s = new \CB\Search(); $query = 'pid: ' . $id; // fetch only a single file if (@$fileId) { $query = 'id: ' . $fileId; } $params = array('fl' => 'id, name, template_id, date, cdate, uid, udate, size', 'fq' => array('dstatus: 0', 'system: [0 TO 1]'), 'sort' => 'sort_name asc'); $data = $s->search($query, 0, 1000, $params); return $data; }
public static function getNodeContent($id, $myPath, $onlyFileId = null) { $s = new \CB\Search(); $query = 'pid:' . $id; $params = array('fl' => 'id,name,template_id,date,cdate,udate,size', 'fq' => array('dstatus:0', 'system:[0 TO 1]'), 'sort' => 'sort_name asc'); if (is_array($onlyFileId)) { $params['fq'][] = 'id:(' . implode(' OR ', $onlyFileId) . ')'; } $data = $s->search($query, 0, 9999, $params); $fileIds = array(); $array = array(); foreach ($data->response->docs as $item) { $el = array('id' => $item->id, 'name' => $item->name, 'template_id' => $item->template_id, 'size' => $item->size, 'cdate' => $item->cdate, 'udate' => $item->udate, 'path' => $myPath . DIRECTORY_SEPARATOR . $item->name); if ($item->template_id != \CB\Config::get('default_file_template')) { $el['path'] = $myPath . DIRECTORY_SEPARATOR . $item->name; } else { $fileIds[] = $el['id']; } $array[$el['id']] = $el; } /* select additional info required for files */ if (!empty($fileIds)) { $res = \CB\DB\dbQuery('SELECT f.id ,CONCAT(c.path, \'/\', f.content_id) `content_path` ,c.md5 ,c.type FROM files f LEFT JOIN files_content c ON f.content_id = c.id WHERE f.id in (' . implode(',', $fileIds) . ')') or die(DB\dbQueryError()); while ($r = $res->fetch_assoc()) { $array[$r['id']] = array_merge($array[$r['id']], $r); } $res->close(); } return $array; }
/** * @dataProvider searchDataProvider */ public function testSearch($search) { $src = new \CB\Search(); $this->assertTrue(is_numeric($src->ping())); $src_response = $src->search('test', 0, 10, []); $this->assertEquals('OK', $src_response->getHttpStatusMessage(), $src_response->getHttpStatusMessage()); $result = Helpers::getIncludeContents(\CB\DOC_ROOT . 'remote/router.php', ['postdata' => $search['postdata']]); $result = json_decode($result, true); $this->assertArraySubset(json_decode($search['expected_response'], true), $result, false, ' Result:' . print_r($result, true) . PHP_EOL . ' Expected:' . print_r(json_decode($search['expected_response'], true), true)); }