Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/CarnetApp/CarnetNextcloud.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhie <phie@phie.ovh>2019-04-09 20:54:21 +0300
committerPhie <phie@phie.ovh>2019-04-09 20:54:21 +0300
commitb1648bab7043fae169aebd8031461fa2c2ad0a51 (patch)
tree9ba763f4be72a728d99f62d7356f6f02c2f710e3
parentc1680e3c8bd56ad20f736700e5740bb6ee7726a8 (diff)
search within cache
-rw-r--r--lib/Command/Search.php46
-rw-r--r--lib/Misc/CacheManager.php20
2 files changed, 57 insertions, 9 deletions
diff --git a/lib/Command/Search.php b/lib/Command/Search.php
index 787fd08..7119858 100644
--- a/lib/Command/Search.php
+++ b/lib/Command/Search.php
@@ -10,7 +10,8 @@ use Symfony\Component\Console\Output\OutputInterface;
use OCP\Files\File;
use OCP\Files\IRootFolder;
use OCP\Files\NotFoundException;
-
+use OCA\Carnet\Misc\CacheManager;
+use OCP\IDBConnection;
class Search extends Command {
private $output;
@@ -23,10 +24,11 @@ class Search extends Command {
* @param string $appName
* @param IRootFolder $rootFolder
*/
-public function __construct($AppName, $RootFolder, $Config){
+public function __construct($AppName, $RootFolder, $Config, IDBConnection $IDBConnection){
parent::__construct();
$this->appName = $AppName;
$this->Config = $Config;
+ $this->db = $IDBConnection;
$this->rootFolder = $RootFolder;
}
@@ -72,10 +74,35 @@ protected function execute(InputInterface $input, OutputInterface $output) {
$query = strtolower($query);
echo "searching ".$query;
+ $this->data = array();
+ $this->pathArray = array();
+ $this->searchInCache($query);
$this->search($path, $this->CarnetFolder->get($path), $query,0);
- $data = json_decode( $this->searchCache->getContent());
- array_push($data, "end_of_search");
- $this->searchCache->putContent(json_encode($data));
+ //$data = json_decode( $this->searchCache->getContent());
+ array_push($this->data, "end_of_search");
+ $this->searchCache->putContent(json_encode($this->data));
+}
+
+private function searchInCache($query){
+ $cache = new CacheManager($this->db, $this->CarnetFolder);
+ $metadataFromCache = $cache->search($query);
+ if($this->searchCache){
+ foreach($metadataFromCache as $path => $mTime){
+ $this->output->writeln('found in '.$path);
+
+ $file = array();
+ $file['name'] = "none";
+ $file['path'] = $path;
+ $file['isDir'] = false;
+ $file['mtime'] = $mTime;
+
+ array_push($this->data, $file);
+ array_push($this->pathArray, $path);
+
+ }
+ $this->searchCache->putContent(json_encode($this->data));
+
+ }
}
private function getCacheFolder(){
@@ -96,9 +123,8 @@ private function writeFound($relativePath, $in){
$file['path'] = $relativePath."/".$inf->getName();
$file['isDir'] = $inf->getType() === "dir";
$file['mtime'] = $inf->getMtime();
- $data = json_decode( $this->searchCache->getContent());
- array_push($data, $file);
- $this->searchCache->putContent(json_encode($data));
+ array_push($this->data, $file);
+ $this->searchCache->putContent(json_encode($this->data));
}
}
private function search($relativePath, $folder, $query, $curDepth){
@@ -113,7 +139,9 @@ private function search($relativePath, $folder, $query, $curDepth){
}
else{
-
+ if(in_array($relativePath."/".$in->getName(), $this->pathArray)){
+ continue;
+ }
if(strstr(strtolower($this->removeAccents($in->getName())), $query)){
$this->writeFound($relativePath, $in);
continue;
diff --git a/lib/Misc/CacheManager.php b/lib/Misc/CacheManager.php
index 0585872..e3535f8 100644
--- a/lib/Misc/CacheManager.php
+++ b/lib/Misc/CacheManager.php
@@ -125,5 +125,25 @@ class CacheManager{
$stmt->closeCursor();
return $array;
}
+
+ public function search($query){
+ $arrayFullPath = array();
+ $sql = 'SELECT * FROM `*PREFIX*carnet_metadata` ' .
+ 'WHERE path LIKE ? AND CONVERT(metadata USING utf8) LIKE _utf8 ? COLLATE utf8_general_ci';
+ $args = array();
+ array_push($args, $this->carnetFolder->getPath()."/%");
+
+ array_push($args, "%".$query."%");
+ $stmt = $this->db->prepare($sql);
+ $stmt->execute($args);
+ $array = array();
+ $fetched = $stmt->fetchAll();
+ foreach ($fetched as $row){
+ $array[substr($row['path'], strlen($this->carnetFolder->getPath())+1)] = json_decode($row['last_modification_file']);
+ }
+
+ $stmt->closeCursor();
+ return $array;
+ }
}
?> \ No newline at end of file