Download the PHP package loupe/matcher without Composer
On this page you can find all versions of the php package loupe/matcher. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download loupe/matcher
More information about loupe/matcher
Files in loupe/matcher
Informations about the package matcher
Loupe Matcher
A PHP library for search term highlighting and text snippet generation. Transform search results into user-friendly formatted text with highlighted matches and contextual cropping.
Lorem ipsum dolor sit amet, consetetur [...] no sea takimata sanctus est lorem est ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur [...] dolore te feugait nulla facilisi lorem ipsum dolor sit amet, consectetuer [...]
[!CAUTION] Work in progress. Expect frequent changes to API and functionality.
Installation
Quick Start
Here's a simple example of how to use Loupe Matcher to highlight search terms in a text document and crop around the highlights:
Core Components
Tokenizer
Purpose: Breaks text into searchable tokens (words, phrases, terms) for accurate matching.
The Tokenizer
converts strings into TokenCollection
objects, handling:
- Word boundaries using
ext-intl
rules - Phrase groups (quoted terms like
"exact phrase"
) - Negated terms (prefixed with
-
) - Locale-specific tokenization
Matcher
Purpose: Finds which tokens in your text match the search query.
The Matcher
compares tokenized text against search terms, with support for:
- Stop word filtering (ignore common words like "the", "and")
- Match span calculation (start/end positions)
- Flexible matching between token collections
Formatter
Purpose: Combines matching and highlighting to create formatted output with context.
The Formatter
orchestrates the entire process:
- Highlights matched terms with HTML tags
- Crops text to show relevant context around matches
- Configurable through
FormatterOptions
Advanced Usage
Custom Tokenizer
Implement TokenizerInterface
for specialized tokenization:
Pre-highlighted Text Cropping
When you already have highlighted text that needs cropping:
Using Pre-calculated Matches
When you already have a TokenCollection
of matches (e.g., from a previous search operation or external source), you can format text directly without re-calculating matches. This approach is useful when your search engine already provides match information or you want to cache match results for performance.
All versions of matcher with dependencies
ext-intl Version *