Skip to content

Commit

Permalink
Merge pull request #1843 from nextcloud/maintenance/remove-dead-searc…
Browse files Browse the repository at this point in the history
…h-code

Dropped old polyfill code
  • Loading branch information
christianlupus committed Oct 12, 2023
2 parents 4920340 + b4d935b commit 2ec2345
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 64 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -79,6 +79,8 @@
[#1822](https://github.com/nextcloud/cookbook/pull/1822) @christianlupus
- Added new description in README to external app
[#1837](https://github.com/nextcloud/cookbook/pull/1837) @VincentMeilinger
- Drop old polyfill code related to global search
[#1843](https://github.com/nextcloud/cookbook/pull/1843) @christianlupus


## 0.10.2 - 2023-03-24
Expand Down
120 changes: 56 additions & 64 deletions lib/Search/Provider.php
Expand Up @@ -11,81 +11,73 @@
use OCP\Search\ISearchQuery;
use OCP\Search\SearchResult;
use OCP\Search\SearchResultEntry;
use OCP\Util;

// IProvider requies NC >= 20
// Remove conditional once we end support for NC 19
if (Util::getVersion()[0] >= 20) {
class Provider implements IProvider {
/** @var IL10N */
private $l;
class Provider implements IProvider {
/** @var IL10N */
private $l;

/** @var IURLGenerator */
private $urlGenerator;
/** @var IURLGenerator */
private $urlGenerator;

/** @var RecipeService */
private $recipeService;
/** @var RecipeService */
private $recipeService;

public function __construct(
IL10n $il10n,
IURLGenerator $urlGenerator,
RecipeService $recipeService
) {
$this->l = $il10n;
$this->urlGenerator = $urlGenerator;
$this->recipeService = $recipeService;
}
public function __construct(
IL10n $il10n,
IURLGenerator $urlGenerator,
RecipeService $recipeService
) {
$this->l = $il10n;
$this->urlGenerator = $urlGenerator;
$this->recipeService = $recipeService;
}

public function getId(): string {
return Application::APP_ID;
}
public function getId(): string {
return Application::APP_ID;
}

public function getName(): string {
return $this->l->t('Recipes');
}
public function getName(): string {
return $this->l->t('Recipes');
}

public function getOrder(string $route, array $routeParameters): int {
if (strpos($route, 'files' . '.') === 0) {
return 25;
} elseif (strpos($route, Application::APP_ID . '.') === 0) {
return -1;
}
return 4;
public function getOrder(string $route, array $routeParameters): int {
if (strpos($route, 'files' . '.') === 0) {
return 25;
} elseif (strpos($route, Application::APP_ID . '.') === 0) {
return -1;
}
return 4;
}

public function search(IUser $user, ISearchQuery $query): SearchResult {
$recipes = $this->recipeService->findRecipesInSearchIndex($query->getTerm());
$result = array_map(
function (array $recipe) use ($user): SearchResultEntry {
$id = $recipe['recipe_id'];
public function search(IUser $user, ISearchQuery $query): SearchResult {
$recipes = $this->recipeService->findRecipesInSearchIndex($query->getTerm());
$result = array_map(
function (array $recipe) use ($user): SearchResultEntry {
$id = $recipe['recipe_id'];

$subline = '';
$category = $recipe['category'];
if ($category !== null) {
// TRANSLATORS Will be shown in search results, listing the recipe category, e.g., 'in Salads'
$subline = $this->l->t('in %s', [$category]);
}
$subline = '';
$category = $recipe['category'];
if ($category !== null) {
// TRANSLATORS Will be shown in search results, listing the recipe category, e.g., 'in Salads'
$subline = $this->l->t('in %s', [$category]);
}

return new SearchResultEntry(
// Thumb image
$this->urlGenerator->linkToRoute('cookbook.recipe.image', ['id' => $id, 'size' => 'thumb']),
// Name as title
$recipe['name'],
// Category as subline
$subline,
// Link to Vue route of recipe
$this->urlGenerator->linkToRouteAbsolute('cookbook.main.index') . '#/recipe/' . $id
);
}, $recipes
);
return new SearchResultEntry(
// Thumb image
$this->urlGenerator->linkToRoute('cookbook.recipe.image', ['id' => $id, 'size' => 'thumb']),
// Name as title
$recipe['name'],
// Category as subline
$subline,
// Link to Vue route of recipe
$this->urlGenerator->linkToRouteAbsolute('cookbook.main.index') . '#/recipe/' . $id
);
}, $recipes
);

return SearchResult::complete(
$this->getName(),
$result
);
}
}
} else {
class Provider {
return SearchResult::complete(
$this->getName(),
$result
);
}
}

0 comments on commit 2ec2345

Please sign in to comment.