adachsoft/text-search

A PHP library for exact, regular-expression, and similarity-based text search.

Maintainers

Package info

gitlab.com/a.adach/text-search

Issues

pkg:composer/adachsoft/text-search

Transparency log

Statistics

Installs: 7

Dependents: 0

Suggesters: 0

Stars: 0

v0.1.0 2026-08-20 05:59 UTC

This package is auto-updated.

Last update: 2026-08-20 04:04:25 UTC


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 matching
  • regex — regular-expression matching
  • similarity — 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.