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>2021-01-20 19:41:54 +0300
committerPhie <phie@phie.ovh>2021-01-20 19:41:54 +0300
commit989e13c160bee9076987a2ccf014e098784d3caf (patch)
tree4b37a63f913f80d3e70d84b3a9f85972ebb9a2d0
parentab19f9c79df0a602a0c06e9dc86ff0ab9e2b09ad (diff)
fix search in folder notes
-rw-r--r--lib/Misc/NoteUtils.php13
-rw-r--r--lib/Misc/Search.php43
2 files changed, 46 insertions, 10 deletions
diff --git a/lib/Misc/NoteUtils.php b/lib/Misc/NoteUtils.php
index bbb3e50..f923bbb 100644
--- a/lib/Misc/NoteUtils.php
+++ b/lib/Misc/NoteUtils.php
@@ -2,6 +2,15 @@
namespace OCA\Carnet\Misc;
class NoteUtils{
public static $defaultCarnetNotePath = "Documents/QuickNote";
+
+ public static function endsWith($string, $endString)
+ {
+ $len = strlen($endString);
+ if ($len == 0) {
+ return true;
+ }
+ return (substr($string, -$len) === $endString);
+ }
public static function getTextFromHTML($html){ //not optimized at alllll....
return
//remove first and last br
@@ -24,6 +33,10 @@ class NoteUtils{
return mb_substr($text, 0, 150);
}
+ public static function isNote($path){
+ return self::endsWith($path, ".sqd");
+ }
+
public static function removeAccents($str) {
$a = array('À', 'Á', 'Â', 'Ã', 'Ä', 'Å', 'Æ', 'Ç', 'È', 'É', 'Ê', 'Ë', 'Ì', 'Í', 'Î', 'Ï', 'Ð', 'Ñ', 'Ò', 'Ó', 'Ô', 'Õ', 'Ö', 'Ø', 'Ù', 'Ú', 'Û', 'Ü', 'Ý', 'ß', 'à', 'á', 'â', 'ã', 'ä', 'å', 'æ', 'ç', 'è', 'é', 'ê', 'ë', 'ì', 'í', 'î', 'ï', 'ñ', 'ò', 'ó', 'ô', 'õ', 'ö', 'ø', 'ù', 'ú', 'û', 'ü', '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', 'Ί', 'ί', 'ϊ', 'ΐ', 'Ύ', 'ύ', 'ϋ', 'ΰ', 'Ή', 'ή');
$b = array('A', 'A', 'A', 'A', 'A', 'A', 'AE', 'C', 'E', 'E', 'E', 'E', 'I', 'I', 'I', 'I', 'D', 'N', 'O', 'O', 'O', 'O', 'O', 'O', 'U', 'U', 'U', 'U', 'Y', 's', 'a', 'a', 'a', 'a', 'a', 'a', 'ae', 'c', 'e', 'e', 'e', 'e', 'i', 'i', 'i', 'i', 'n', 'o', 'o', 'o', 'o', 'o', 'o', 'u', 'u', 'u', 'u', 'y', 'y', 'A', 'a', 'A', 'a', 'A', 'a', 'C', 'c', 'C', 'c', 'C', 'c', 'C', 'c', 'D', 'd', 'D', 'd', 'E', 'e', 'E', 'e', 'E', 'e', 'E', 'e', 'E', 'e', 'G', 'g', 'G', 'g', 'G', 'g', 'G', 'g', 'H', 'h', 'H', 'h', 'I', 'i', 'I', 'i', 'I', 'i', 'I', 'i', 'I', 'i', 'IJ', 'ij', 'J', 'j', 'K', 'k', 'L', 'l', 'L', 'l', 'L', 'l', 'L', 'l', 'l', 'l', 'N', 'n', 'N', 'n', 'N', 'n', 'n', 'O', 'o', 'O', 'o', 'O', 'o', 'OE', 'oe', 'R', 'r', 'R', 'r', 'R', 'r', 'S', 's', 'S', 's', 'S', 's', 'S', 's', 'T', 't', 'T', 't', 'T', 't', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'W', 'w', 'Y', 'y', 'Y', 'Z', 'z', 'Z', 'z', 'Z', 'z', 's', 'f', 'O', 'o', 'U', 'u', 'A', 'a', 'I', 'i', 'O', 'o', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'A', 'a', 'AE', 'ae', 'O', 'o', 'Α', 'α', 'Ε', 'ε', 'Ο', 'ο', 'Ω', 'ω', 'Ι', 'ι', 'ι', 'ι', 'Υ', 'υ', 'υ', 'υ', 'Η', 'η');
diff --git a/lib/Misc/Search.php b/lib/Misc/Search.php
index 8d4c7c0..53c511b 100644
--- a/lib/Misc/Search.php
+++ b/lib/Misc/Search.php
@@ -109,7 +109,7 @@ private function search($relativePath, $folder, $query, $curDepth){
$this->current = $this->current+1;
//$this->output->writeln('in '.$in->getPath());
- if($in->getFileInfo()->getType() === "dir"){
+ if($in->getFileInfo()->getType() === "dir" && !NoteUtils::isNote($in->getName())){
if($curDepth<30) //might be a problem in nc db
$endWell = $this->search(($relativePath!==""?$relativePath."/":"").$in->getName()."/", $in, $query, $curDepth+1);
}
@@ -123,10 +123,8 @@ private function search($relativePath, $folder, $query, $curDepth){
}
try {
- $zipFile = new \PhpZip\ZipFile();
- $zipFile->openFromStream($in->fopen("r"));
- try {
- $metadata = json_decode($zipFile->getEntryContents("metadata.json"));
+ if($in->getFileInfo()->getType() === "dir"){
+ $metadata = json_decode($in->get("metadata.json")->getContent());
$hasFound = false;
if (is_object ($metadata))
{
@@ -141,12 +139,37 @@ private function search($relativePath, $folder, $query, $curDepth){
if($hasFound){
continue;
}
-
- } catch(Exception $e){
+ $index = $in->get("index.html")->getContent();
+ if(trim ($query) !== "" && strstr(strtolower(NoteUtils::removeAccents($index)), $query)){
+ $this->writeFound($relativePath,$in);
+ }
}
- $index = $zipFile->getEntryContents("index.html");
- if(trim ($query) !== "" && strstr(strtolower(NoteUtils::removeAccents($index)), $query)){
- $this->writeFound($relativePath,$in);
+ else {
+ $zipFile = new \PhpZip\ZipFile();
+ $zipFile->openFromStream($in->fopen("r"));
+ try {
+ $metadata = json_decode($zipFile->getEntryContents("metadata.json"));
+ $hasFound = false;
+ if (is_object ($metadata))
+ {
+ foreach($metadata->keywords as $keyword){
+ if(strstr(NoteUtils::removeAccents(strtolower($keyword)), $query)){
+ $this->writeFound($relativePath,$in);
+ $hasFound = true;
+ break;
+ }
+ }
+ }
+ if($hasFound){
+ continue;
+ }
+
+ } catch(Exception $e){
+ }
+ $index = $zipFile->getEntryContents("index.html");
+ if(trim ($query) !== "" && strstr(strtolower(NoteUtils::removeAccents($index)), $query)){
+ $this->writeFound($relativePath,$in);
+ }
}
} catch(\OCP\Files\NotFoundException $e) {
} catch(\PhpZip\Exception\ZipException $e){