KMP and the Failure Function
In short: KMP precomputes a failure function π, the longest border
(a proper prefix that is also a suffix) of every prefix of the pattern, in
O(m). On a mismatch the search falls back to the next shorter border instead
of restarting, so the text pointer never moves backwards and the whole search
is O(n) worst case, guaranteed — unlike Rabin-Karp's hash gamble or the naive
scan's O(n · m).

Rabin-Karp makes the windows that don't match cheap, but it is still a gamble. A
collision costs a wasted check, and a text full of genuine near-misses can still
cost n · m. Quarry has a harder requirement too: it tails live logs. Text
arrives a chunk at a time, and once a chunk has gone past, Quarry can't read it
again. A matcher that backs up to "try the next alignment" is useless there.
The Knuth-Morris-Pratt algorithm (KMP) fixes both problems. It is exact, it is O(n + m) in the worst case, and its text pointer never moves backwards. The idea behind it is that the naive search keeps throwing away something it already knows.
What the naive search forgets
Search for abcabd in abcabcabd. The first five characters match, and then the
text's c meets the pattern's d. The naive search slides the pattern one place
right and starts reading again from text index 1.
But at that moment you know the last five text characters: they are abcab,
because they just matched the pattern. So you don't need the text to decide which
alignments could still work. An alignment can only succeed if the start of the
pattern lines up with the end of what you've already matched, which means a
prefix of the pattern has to equal a suffix of abcab. The longest such overlap
is ab. So slide the pattern until its ab sits under the text's last ab, and
carry on from the same text position.