KeywordSearch
- interface KeywordSearchInterface
-
- Fully qualified name
-
\Netresearch\
Nr Llm\ Service\ Retrieval\ Keyword Search Interface
Public keyword-search facade over the site-search retrieval cascade (ADR-071: Public keyword-search facade over the retrieval cascade). Searches the first available backend (Solr, ke_search, indexed_search, database fallback), always filtered public-only — hits are what the anonymous visitor could read.
Input is clamped, never rejected, and any backend failure degrades to an empty result: the facade never throws.
- search ( string $query, int $limit, ?int $languageId = null) : array
-
Run a public-only keyword search. The query is trimmed and truncated to 200 characters; a query shorter than 2 characters returns an empty list. The limit is clamped to 1–20; a negative language id is clamped to 0. Hits are deduplicated by URL and capped at the limit.
- param string $query
-
Free-text query
- param int $limit
-
Maximum number of hits (clamped to 1–20)
- param ?int $languageId
-
sys_language uid; null means default (0)
- Returns
-
list<KeywordHit> — empty when nothing matched, the query is too short, or no backend is available
- class KeywordHit
-
- Fully qualified name
-
\Netresearch\
Nr Llm\ Service\ Retrieval\ Keyword Hit
One keyword-search hit. Final readonly DTO.
Service variants
Two container registrations exist (ADR-071: Public keyword-search facade over the retrieval cascade):
Keyword— the full cascade including the database LIKE fallback. Wire it via constructor type hint or resolve it from the container.Search Interface nr_llm.keyword_search.index_backed— a named variant that excludes the fallback tier. Use it when "index unavailable" must yield an empty result instead of LIKE hits (e.g. hybrid dense+sparse fusion). Itsisanswers for index-backed engines only.Available ()
Usage
use Netresearch\NrLlm\Service\Retrieval\KeywordSearchInterface;
final class PageFinder
{
public function __construct(
private readonly KeywordSearchInterface $keywordSearch,
) {}
public function findCandidates(string $topic): array
{
if (!$this->keywordSearch->isAvailable()) {
return [];
}
return $this->keywordSearch->search($topic, 10);
}
}
Wiring the index-backed-only variant:
Vendor\Ext\Search\SparseArm:
arguments:
$keywordSearch: '@nr_llm.keyword_search.index_backed'