Skip to content

Commit

Permalink
Bugfix: search must not include debug projects per default
Browse files Browse the repository at this point in the history
  • Loading branch information
dmetzner committed Jul 25, 2020
1 parent a050cb9 commit e4f8b90
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 8 deletions.
3 changes: 2 additions & 1 deletion config/packages/fos_elastica.yaml
Expand Up @@ -28,6 +28,7 @@ fos_elastica:
name: { boost: 3 }
private: ~
visible: ~
debug_build: ~
getTagsString: ~
getExtensionsString: ~
persistence:
Expand Down Expand Up @@ -60,4 +61,4 @@ fos_elastica:
model: App\Entity\User
provider: ~
finder: ~
listener: ~
listener: ~
15 changes: 13 additions & 2 deletions src/Catrobat/Controller/Api/SearchController.php
Expand Up @@ -2,6 +2,7 @@

namespace App\Catrobat\Controller\Api;

use App\Catrobat\Requests\AppRequest;
use App\Catrobat\Responses\ProgramListResponse;
use App\Entity\ProgramManager;
use Elastica\Query;
Expand All @@ -12,10 +13,16 @@

class SearchController extends AbstractController
{
protected AppRequest $app_request;
private int $DEFAULT_LIMIT = 20;

private int $DEFAULT_OFFSET = 0;

public function __construct(AppRequest $app_request)
{
$this->app_request = $app_request;
}

/**
* @deprecated
*
Expand Down Expand Up @@ -48,8 +55,12 @@ public function searchProgramsAction(Request $request, ProgramManager $program_m

try
{
$programs = $program_manager->search($query, $limit, $offset, $max_version);
$numbOfTotalProjects = $program_manager->searchCount($query, $max_version);
$programs = $program_manager->search(
$query, $limit, $offset, $max_version, null, $this->app_request->isDebugBuildRequest()
);
$numbOfTotalProjects = $program_manager->searchCount(
$query, $max_version, null, $this->app_request->isDebugBuildRequest()
);
}
catch (Exception $e)
{
Expand Down
15 changes: 10 additions & 5 deletions src/Entity/ProgramManager.php
Expand Up @@ -729,16 +729,16 @@ public function getRandomProgramsCount(string $flavor = null, string $max_versio
);
}

public function search(string $query, ?int $limit = 10, int $offset = 0, string $max_version = '0', ?string $flavor = null): array
public function search(string $query, ?int $limit = 10, int $offset = 0, string $max_version = '0', ?string $flavor = null, bool $is_debug_request = false): array
{
$program_query = $this->programSearchQuery($query, $max_version, $flavor);
$program_query = $this->programSearchQuery($query, $max_version, $flavor, $is_debug_request);

return $this->program_finder->find($program_query, $limit, ['from' => $offset]);
}

public function searchCount(string $query, string $max_version = '0', ?string $flavor = null): int
public function searchCount(string $query, string $max_version = '0', ?string $flavor = null, bool $is_debug_request = false): int
{
$program_query = $this->programSearchQuery($query, $max_version, $flavor);
$program_query = $this->programSearchQuery($query, $max_version, $flavor, $is_debug_request);

$paginator = $this->program_finder->findPaginated($program_query);

Expand Down Expand Up @@ -977,7 +977,7 @@ public function getProgram(string $id): array
);
}

private function programSearchQuery(string $query, string $max_version = '0', ?string $flavor = null): BoolQuery
private function programSearchQuery(string $query, string $max_version = '0', ?string $flavor = null, bool $is_debug_request = false): BoolQuery
{
$query = Util::escapeTerm($query);

Expand All @@ -998,6 +998,11 @@ private function programSearchQuery(string $query, string $max_version = '0', ?s
$category_query[] = new Terms('private', [false]);
$category_query[] = new Terms('visible', [true]);

if (!$is_debug_request)
{
$category_query[] = new Terms('debug_build', [false]);
}

if ('0' !== $max_version)
{
$category_query[] = new Range('language_version', ['lte' => $max_version]);
Expand Down

0 comments on commit e4f8b90

Please sign in to comment.