ML Models & Algorithms
Boyer-Moore
In shortA fast exact string-search algorithm that compares a pattern from right to left and skips ahead after mismatches.
Boyer-Moore is a classic algorithm for finding an exact pattern inside a longer piece of text. Published by Robert Boyer and J Strother Moore in 1977, it is one of the best-known string-search algorithms and is very fast in practice. In MLforSEO’s guide to fuzzy matching, it is the flagship example of exact matching, the strict end of the string-matching spectrum.
How it works
A naive search compares the pattern with the text one position at a time, left to right. Boyer-Moore lines the pattern up with the text but compares characters from the end of the pattern backwards. When it finds a mismatch it uses two precomputed tables to jump forward:
- Bad character rule: if the mismatched text character does not appear in the pattern at all, the whole pattern can slide past it.
- Good suffix rule: if part of the pattern already matched, the pattern shifts to the next place that matched part could reappear.
Because of these skips it often inspects only a fraction of the characters, and it tends to get faster as the pattern gets longer. It returns exact matches only: one wrong letter means no match.
How it’s used in SEO and marketing
- Checking whether an exact brand name, product code or phrase appears in thousands of pages, titles or reviews.
- Flagging exact keyword mentions in crawled content before a deeper semantic analysis.
- Pre-filtering large datasets cheaply, so slower fuzzy or semantic methods only run on what is left.
In day-to-day SEO work you rarely implement it yourself. Fast substring search in programming languages, text editors and command-line tools uses Boyer-Moore or related ideas behind the scenes.
Example
You want every product description that mentions “GORE-TEX” across a 50,000-row export. An exact search finds “GORE-TEX” instantly but misses “Goretex” and “gore tex”. That is the point where MLforSEO suggests moving to distance-based matching such as Levenshtein, or phonetic matching, to catch the variants.
Limitations and things to watch
- No tolerance for typos, spacing, plurals or synonyms.
- No understanding of meaning, so “apple” the fruit and “Apple” the brand look the same once case is ignored.
- Searching for many different patterns at once is better handled by multi-pattern algorithms such as Aho-Corasick.
Learn it on MLforSEO
Where Boyer-Moore shows up on MLforSEO
Read about it on the blog
Sources and further reading
Other terms from ML Models & Algorithms
- BERT (Bidirectional Encoder Representations from Transformers)Google's 2018 transformer language model that reads text in both directions to produce context-aware embedding…
- BERTopicA modular topic modelling technique that clusters transformer embeddings and labels each cluster with class-ba…
- BIRCH (Balanced Iterative Reducing and Clustering using Hierarchies)BIRCH (Balanced Iterative Reducing and Clustering using Hierarchies) clusters very large numeric datasets by s…
- BM25A classic ranking function that scores documents by how often query words appear, adjusted for word rarity and…
- c-TF-IDFClass-based TF-IDF: treats each cluster as one document to find the words that best describe it, used by BERTo…
- Centroid-based ClusteringA clustering family that groups data around central points (centroids), each the average of its cluster's memb…
- Convolutional Neural Network (CNN)A deep learning architecture that scans data with small learned filters to detect local patterns; the classic…
- DBSCANDensity-based clustering that groups closely packed points, finds the number of clusters itself and labels iso…
- Decision TreeA supervised model that predicts by asking a series of yes/no questions about the data, branching like a flowc…
