[Help needed] add noIndex to objects
Closed this issue · 1 comments
Mordef commented
Q | A |
---|---|
Bug report? | no |
Feature request? | no |
BC Break report? | no |
RFC? | no |
How can i mark objects to exclude for indexing?
solverat commented
You have multiple options: Either, you may want to modify the Listing for global conditions or you could use the resource candidate validation.
<?php
namespace App\DynamicSearch\EventListener;
use DsTrinityDataBundle\DsTrinityDataEvents;
use DsTrinityDataBundle\Event\AssetListingQueryEvent;
use DsTrinityDataBundle\Event\DocumentListingQueryEvent;
use DynamicSearchBundle\DynamicSearchEvents;
use DynamicSearchBundle\Event\ResourceCandidateEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class ListingQueryListener implements EventSubscriberInterface
{
public static function getSubscribedEvents(): array
{
return [
DsTrinityDataEvents::LISTING_QUERY_ASSETS => ['onAssetListing', 0],
DsTrinityDataEvents::LISTING_QUERY_DOCUMENTS => ['onDocumentListing', 0],
DynamicSearchEvents::RESOURCE_CANDIDATE_VALIDATION => ['validateResourceCandidate', 0]
];
}
public function validateResourceCandidate(ResourceCandidateEvent $e): void
{
$resourceCandidate = $e->getResourceCandidate();
$resource = $resourceCandidate->getResource();
if ($resource instanceof UnwantedEntity) {
$resourceCandidate->setResource(null);
}
// Helper
// $dispatchType = $resourceCandidate->getDispatchType() // like "index" or "delete"
// $isAllowedToModifyResource = $resourceCandidate->isAllowedToModifyResource()
// $isAllowedToModifyDispatchType = $resourceCandidate->isAllowedToModifyDispatchType()
}
public function onAssetListing(AssetListingQueryEvent $e): void
{
$listing = $e->getListing();
$listing->addConditionParam('GLOBAL ASSET LISTING CONDITION');
}
public function onDocumentListing(DocumentListingQueryEvent $e): void
{
$listing = $e->getListing();
$listing->addConditionParam('GLOBAL DOCUMENT LISTING CONDITION');
}
}