DEV Community

Cover image for The Day Our Search Engine Learned Palindromes
Stephen O.
Stephen O.

Posted on

The Day Our Search Engine Learned Palindromes

The problem started with a message that looked harmless.

Arman opened Slack one morning and saw a notification from the support channel:

User report: “Search feels… weird.”

That was it.

No bug report. No screenshots. Just weird.

Arman sighed and opened the site. The search bar sat at the top of the page like it always had. Clean, simple, waiting patiently.

He typed:

server

Results appeared instantly.

Great.

Then he typed:

database

Also fine.

Then he typed:

api

The results were… odd.

The first result was “April 2016 Release Notes.”
The second was “Office Parking Policy.”
The third was a page titled “How to Brew Coffee in the Break Room.”

Arman frowned.

“Interesting priorities.”

He tried another search.

login

Top result: “Company Picnic Photos.”

Now he was intrigued.


The search system itself was simple. A small service indexed content from the database and ranked results based on relevance. It had worked perfectly for years.

So something had changed.

He opened the search service repository and checked recent commits. One stood out immediately.

commit message:
improve search ranking

The author was Nina, one of the newer developers.

Arman opened the diff.

At first it looked reasonable. The ranking formula had been adjusted to weigh different factors: title matches, keyword frequency, page popularity.

Then he reached the bottom of the file.

There was a new rule.

if (content.includes(query)) {
  score += 50;
} 
Enter fullscreen mode Exit fullscreen mode

He nodded slowly.

“Fair enough.”

Then he saw the line directly below it.

if (content.includes(query.split("").reverse().join(""))) {
  score += 50;
}
Enter fullscreen mode Exit fullscreen mode

Arman blinked.

“Why… reversed?”

He scrolled further.

There was a comment.

// helps catch creative user searches 
Enter fullscreen mode Exit fullscreen mode

He leaned back.

“Creative.”

To test it, he typed something unusual into the search bar.

level

The results looked normal.

Then he tried something else.

desserts

The first result was a page titled “Stressed Deployment Guide.”

Arman stared at the screen.

“Wait.”

He typed:

stressed

Top result: “Desserts Menu.”

He rubbed his forehead.

The search engine wasn’t just matching the query—it was also matching the reversed query against every piece of content. Any word that happened to be a reverse of something else would suddenly become highly relevant.

It explained everything.

stressed → desserts
drawer → reward
live → evil

The search system had accidentally become a palindrome detective.

But the real problem was scale.

The site contained thousands of pages. Every query now triggered double the text scans, checking both the original string and its reversed version against huge blocks of content.

Arman opened the performance metrics.

Search queries were taking three times longer than before.

He tested something else.

In the search bar he typed:

god

The top result appeared instantly.

“Dog Adoption Policy.”

Arman stared at the screen for a moment.

Then he opened the code again and removed the reversed-search logic.

He pushed the fix and redeployed.

Within seconds, the search results returned to normal.

api returned API documentation.

login returned authentication pages.

Coffee guides returned only when someone actually searched for coffee.

He posted the resolution in the dev channel.

Root cause: search engine was ranking reversed queries as highly relevant.

A minute later Nina replied.

“Oh yeah! I added that.”

Arman waited.

Another message appeared.

“I read somewhere that users search in unpredictable ways.”

Arman leaned back in his chair.

“That is technically true.”

She replied with a thinking emoji.

“So… keep it?”

Arman looked at the deployment logs, the restored performance graphs, and the search results that once again made sense.

He typed one final message.

“No.”

Across the system, search quietly returned to its old, boring behavior.

And somewhere deep in the Git history, Nina’s comment remained:

// helps catch creative user searches 
Enter fullscreen mode Exit fullscreen mode

For a brief moment in time, the company’s search engine had been able to find desserts when you searched for stress.

And honestly, Arman thought, "that part wasn’t entirely wrong". 🍰💻

Top comments (0)