Scoped Search With Page Redirect Extension

I’m having so much fun with this Page Redirect extension I’ve created. Initially, it was created for two main usecases I have:

  • Automatically set a homepage. For example, it can change the Facebook homepage (Newsfeed) to the Facebook Feeds tab.
  • Open the current YouTube video in Invidious. This removes ads before you watch.

Thanks to the use of regular expressions, the extension helps me in other scenarios as well. The one I want to talk about in this post is scoped search.

Do you feel like Google search quality has degraded over the past few years? I do. If I search for something like “best cities to live in the US,” the entire front page is filled with spam. To get better results, I usually have to scope the search to a specific domain like Reddit.

To do that, I usually just append “reddit” to the end of my search query, like “best cities to live in the US reddit.” However, I still occasionally get results that are not from “reddit.com.” That’s because appending “reddit” is lazy. I should append “site:reddit.com” instead. That’s the correct syntax to tell Google to return results only from “reddit.com.”

You can configure Page Redirect to help you with that. With the following configuration

Origin
^https://www.google.com/search\?.*q=(.+?)\+?(?:%40|@)reddit\b
Destination
https://www.google.com/search?q=$1+site%3Areddit.com

Now when you type: “best cities to live in the US @reddit”, you get redirected automatically to “best cities to live in the US site:reddit.com”. Awesome!

I also have rules set up for searching HackerNews as well. So if I append @hn at the end of my query, I get “site:news.ycombinator.com” appended to my query directly.

Origin
^https://www.google.com/search\?.*q=(.+?)?\+?(?:%40|@)hn\b
Destination
https://www.google.com/search?q=$1+site%3Anews.ycombinator.com

Now, if I search for something, for example “self hosted LLM”, on Google. If the results are not satisfactory, I can quickly append “@reddit” and press Enter. My query gets tranformed to “self hosted LLM site:reddit.com”. In this case, I’d probably get better results if I do a scoped search in a more tech-focused site such as Hacker News. I can remove “site:reddit.com” and add @hn. Now my query turned into “self hosted LLM site:news.ycombinator.com”.

However, I can do better. Removing “site:reddit.com” seems tedious. It would be great if I just add “@hn”, “site:reddit.com” is replaced with “site:news.ycombinator.com”. I can do that too! Here’s the configuration that does just that:

Origin
^https://www.google.com/search\?.*q=(.+?)\+(site%3A.+?)\+?(?:%40|@)reddit\b
Destination
https://www.google.com/search?q=$1+site%3Areddit.com

Note: I’ve inserted \+(site%3A.+?) into the original regular expression.

Now if I am currently searching with “self hosted LLM site:reddit.com”, I can simply append @hn to the query, i.e. “self hosted LLM site:reddit.com @hn”, the query will be rewritten to “self hosted LLM site:news.ycombinator.com”!