-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsearch.php
52 lines (45 loc) · 1.43 KB
/
search.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php
if(!OCA\FilesSharding\Lib::checkIP()){
http_response_code(401);
exit;
}
class OC_Sharded_Search_Result extends OC_Search_Result {
public $parentdir;
public $parentid;
public function __construct($searchResult) {
$this->id = $searchResult->id;
$this->name = $searchResult->name;
$this->link = $searchResult->link;
$this->type = $searchResult->type;
}
}
$query=(isset($_POST['query']))?$_POST['query']:'';
$user_id=(isset($_POST['user_id']))?$_POST['user_id']:'';
if(!isset($_POST['user_id'])){
http_response_code(401);
exit;
}
if($query) {
\OC_User::setUserId($user_id);
\OC_Util::setupFS($user_id);
OC_Search::removeProvider('OC\Search\Provider\File');
OC_Search::removeProvider('OCA\Search_Lucene\Lucene');
OC_Search::removeProvider('OCA\FilesSharding\SearchShared');
$result = \OC::$server->getSearch()->search($query);
$shardedResult = [];
foreach($result as $res){
if(empty($res->link) || empty($res->id)){// The search indices are apparently often messed up, discard bad hits
continue;
}
$shRes = new OC_Sharded_Search_Result($res);
$shRes->userid = $user_id;
$shRes->parentdir = dirname($res->link);
$shRes->parentid = empty($shRes->parentdir)?'':\OCA\FilesSharding\Lib::getFileId($shRes->parentdir, $user_id);
$shardedResult[] = $shRes;
}
\OCP\Util::writeLog('search', 'Search results: '.json_encode($shardedResult), \OC_Log::WARN);
OC_JSON::encodedPrint($shardedResult);
}
else {
echo 'false';
}