domainEngine = $domainEngine; } /** * Detect the media type for the given SearchContext. * Returns a new SearchContext with the resolved MediaType applied. * * @param SearchContext $context Search\SearchContext (pipeline context) */ public function detect(SearchContext $context): SearchContext { $query = trim($context->getRequest()->getQuery()); if ($query === '') { return $context->withResolvedMediaType(MediaType::UNKNOWN); } $hint = $context->getRequest()->getMediaType(); $hint = ($hint === MediaType::AUTO || $hint === MediaType::UNKNOWN) ? null : $hint; try { $domainResolution = $this->domainEngine->resolve($query, $hint); if ($domainResolution->requiresOperatorInput()) { return $context->withResolvedMediaType(MediaType::UNKNOWN); } return $context->withResolvedMediaType($domainResolution->getResolvedDomain()); } catch (DiscoveryUnresolvedException $e) { return $context->withResolvedMediaType(MediaType::UNKNOWN); } } }