r/howdidtheycodeit • u/stable_maple • Apr 17 '22
How common does Google use regex in its search algorithm?
This thought just occurred to me while searching through the AUR. I know that Google keeps its "secret formula" close to the chest, but we still get a peek every now and again through interviews or leaks and the like. Surely regular expressions features heavily in Google's search algorithm, right?
29
Upvotes
17
u/fiskfisk Apr 17 '22
Why do you assume that regular expressions are an important tool in search algorithms?
In general you want to retain as much semantic meaning as possible through the whole stack, while regexes are crude text matching machines.
You might want to look at how tools like Lucene, Solr, Elasticsearch works to get a firmer basic undestanding of how a document search engine can be built. Google's search is far more advanced than what either of these offer, but it'll give you the base knowledge that a search engine can be built on top of.
19
u/kodbraker Apr 17 '22
There are a lot going on than a regex search. As far as I know, google keeps an inverted index of word stems.
For ranking or relevance calculating? I've no idea but I still wouldn't think it's a good fit scenario for regex.
11
u/drhayes9 Apr 17 '22
No, not really.
Regex works great for finding specific patterns of text based on a specialized language. But Google searches aren't regular expressions, they're just unstructured text.
Google searches look more like full-text searches.
5
u/ERROR_ Apr 17 '22
That's an odd question, like asking 'how often do chefs use screwdrivers?'. I'm sure they use them sometimes, and while they're an important tool, it's not directly related to their main job.
2
u/[deleted] Apr 17 '22
I believe google uses a tree like structure. This way u want to predict the next word. Look up the most common strings beginning with what was entered by searching through remaining nodes which are probabilistically ranked I imagine. I forgot what textbook I was reading this in but they gave a nice description of the structure
1
u/GameFeelings Apr 17 '22
Google is basically doing the inverse: while you might code as if you look through a document for the first time every time, google does the opposite.
Every page that gets added to the system first gets indexed and ranked, and added to a lot of pre-generated graphs and indexes.
Then google takes your query, tries to understand how your query relates to all their indexes, and tries to find the most relevant result it can get within its allowed timeframe.
Google probably continues looking for your related stuff even after your query. To optimize for your further searches (probably in de same related area). Or even better: while you are typing its already predicting where you are going (and thus buying its algorithms more time)
Its just searching optimized to the extreme with all possible optimizations carried out. And all the while its not only searching, but also ranking.
Funny thing you might find out if you start writing your own search systems: its the ranking thats the hardest part. Finding something fast is just a matter of indexing. Finding the right thing is much much much MUCH harder. And there is where the secret sauce is.
-3
u/echoAnother Apr 17 '22
Okay, here all people saying that are not common. They are not the most important thing, but the base. Tokenization and steaming are work for regex.
0
u/[deleted] Apr 17 '22
[deleted] — view deleted comment