adachsoft / text-search
A PHP library for exact, regular-expression, and similarity-based text search.
v0.1.0
2026-08-20 05:59 UTC
Requires
- php: ^8.3
- ext-mbstring: *
- adachsoft/collection: 3.0.2
Requires (Dev)
- adachsoft/php-code-style: ^0.5.0
- friendsofphp/php-cs-fixer: ^3.95
- phpstan/phpstan: ^2.2
- phpunit/phpunit: ^13.1
- rector/rector: ^2.4
- symplify/phpstan-rules: ^14.12
README
A PHP library for searching text with exact, regular-expression, and similarity-based matching strategies.
Requirements
- PHP 8.3 or later
Installation
Install the library with Composer:
composer require adachsoft/text-search
Usage
Create a search engine with the default matcher configuration and search a text using a phrase collection:
<?php
declare(strict_types=1);
use AdachSoft\TextSearch\Collection\PhraseCollection;
use AdachSoft\TextSearch\SearchEngineFactory;
$engine = SearchEngineFactory::createDefault();
$phrases = new PhraseCollection(['search phrase']);
$results = $engine->search(
'Text containing the search phrase.',
$phrases,
'exact',
);
SearchEngineFactory::createDefault() registers the following matchers:
exact— exact text matchingregex— regular-expression matchingsimilarity— similarity-based matching
The similarity threshold can be configured when creating the default engine:
$engine = SearchEngineFactory::createDefault(0.9);
Main Components
SearchEngine— coordinates registered matchers and performs searches.SearchEngineFactory— creates a search engine with the default matcher configuration.MatcherInterface— defines the matcher contract.TokenizerInterface— defines the tokenization contract.SimilarityStrategyInterface— defines the similarity calculation contract.ContextExtractorInterface— defines match-context extraction.PositionResolverInterface— defines match-position resolution.
The library also provides immutable value objects and specialized collections for phrases, tokens, match results, contexts, positions, and search options.
License
This library is released under the MIT License.