toflar/state-set-index
PHP implementation of the State Set Index algorithm for fast typo-tolerant (Levenshtein) similarity search over very large string sets with small indexes. Extends the paper with transposition support, caching snapshots, and pluggable alphabets/storage.
The state-set-index package is a specialized approximate string-matching algorithm optimized for fuzzy search (Levenshtein/Damerau-Levenshtein distance) in large datasets. While it is not a traditional state management tool, its core functionality aligns with Laravel use cases where search, autocomplete, or typo-tolerant queries are critical, such as:
The package’s state-set-based indexing is not a direct replacement for Laravel’s built-in state management (e.g., sessions, caches) but excels in string similarity search, where traditional solutions (e.g., LIKE queries, full-text search) are inefficient.
InMemoryStateSet, InMemoryDataStore), custom persistent storage (e.g., Redis, MySQL) can be implemented via interfaces (StateSetInterface, DataStoreInterface).Config parameters (maxIndexLength, alphabetSize). Poor configuration may lead to false positives/negatives or degraded performance.Utf8Alphabet supports Unicode, edge cases (e.g., emojis, rare scripts) may require custom AlphabetInterface implementations.pg_trgm, Elasticsearch) already in use?Config parameters and debugging false matches?pg_trgm or Elasticsearch been considered for fuzzy search?str_similarity() with a threshold) suffice?scopeFuzzyLike())./api/search?q=query&maxDistance=2).StateSetInterface and DataStoreInterface using:
WHERE id IN (...)).LIKE '%query%').pg_trgm if portability is a concern).config('search.fuzzy.max_distance')) for flexibility.state-set-index for candidate generation.Builder with custom methods (e.g., fuzzyWhere()).StateSetInterface/DataStoreInterface for Redis/MySQL.Config parameters for performance/accuracy.Config parameters (maxIndexLength, alphabetSize) require domain-specific tuning. Document optimal settings for key use cases (e.g., "For product names, use maxIndexLength=8")..env in Laravel).index() calls).Config or Alphabet mappings.$stateSetIndex->findAcceptedStrings() to debug intermediate results.maxIndexLength and alphabetSize based on query latency and memory usage.How can I help you explore Laravel packages today?