From 71f7e60f603396a9c0dfbb3e5f539c154fe97fcc Mon Sep 17 00:00:00 2001 From: Maxence Lange Date: Wed, 12 Jul 2023 13:41:46 -0100 Subject: [PATCH] probeCircles on search Signed-off-by: Maxence Lange --- lib/Db/CoreQueryBuilder.php | 13 +--- .../Version0028Date20230705222601.php | 62 +++++++++++++++++++ lib/Service/SearchService.php | 5 +- psalm.xml | 1 + 4 files changed, 66 insertions(+), 15 deletions(-) create mode 100644 lib/Migration/Version0028Date20230705222601.php diff --git a/lib/Db/CoreQueryBuilder.php b/lib/Db/CoreQueryBuilder.php index 306cf2378..311a5937c 100644 --- a/lib/Db/CoreQueryBuilder.php +++ b/lib/Db/CoreQueryBuilder.php @@ -405,18 +405,7 @@ public function filterCircleDetails(Circle $circle): void { } $orX->add($andX); } - if ($circle->getDescription() !== '') { - $orDescription = $expr->orX(); - foreach (explode(' ', $circle->getDescription()) as $word) { - $orDescription->add( - $expr->iLike( - $this->getDefaultSelectAlias() . '.' . 'description', - $this->createNamedParameter('%' . $word . '%') - ) - ); - } - $orX->add($orDescription); - } + if ($orX->count() > 0) { $this->andWhere($orX); } diff --git a/lib/Migration/Version0028Date20230705222601.php b/lib/Migration/Version0028Date20230705222601.php new file mode 100644 index 000000000..8eec8fe0e --- /dev/null +++ b/lib/Migration/Version0028Date20230705222601.php @@ -0,0 +1,62 @@ + + * @copyright 2022 + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ + + +namespace OCA\Circles\Migration; + +use Closure; +use Doctrine\DBAL\Schema\SchemaException; +use OCP\DB\ISchemaWrapper; +use OCP\Migration\IOutput; +use OCP\Migration\SimpleMigrationStep; +use Psr\Log\LoggerInterface; + +class Version0028Date20230705222601 extends SimpleMigrationStep { + public function __construct( + private LoggerInterface $logger + ) { + } + + public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper { + /** @var ISchemaWrapper $schema */ + $schema = $schemaClosure(); + + try { + $table = $schema->getTable('circles_circle'); + if (!$table->hasIndex('dname')) { + $table->addIndex(['display_name'], 'dname'); + } + } catch (SchemaException $e) { + $this->logger->warning('Could not find circles_circle', ['exception' => $e]); + } + + return $schema; + } +} diff --git a/lib/Service/SearchService.php b/lib/Service/SearchService.php index f1573051c..1d2d17858 100644 --- a/lib/Service/SearchService.php +++ b/lib/Service/SearchService.php @@ -106,7 +106,7 @@ public function unifiedSearch(string $term, array $options): array { $probe = $this->generateSearchProbe($term, $options); try { - $circles = $this->circleService->getCircles($probe); + $circles = $this->circleService->probeCircles($probe); } catch (InitiatorNotFoundException $e) { return []; } @@ -154,8 +154,7 @@ private function generateSearchProbe(string $term, array $options): CircleProbe ->filterBackendCircles(); $circle = new Circle(); - $circle->setDisplayName($term) - ->setDescription($term); + $circle->setDisplayName($term); $probe->setFilterCircle($circle); diff --git a/psalm.xml b/psalm.xml index eac4c1739..81ca9131b 100644 --- a/psalm.xml +++ b/psalm.xml @@ -25,6 +25,7 @@ +