Make Google Work from the URL Bar Like it Used To
The quotes, plusses and minuses work without going to "Advanced Search"
If you’re like me, you remember back in the day when you could actually type quotes around what you want google to search for. Putting something in quotations means “must include” and prepending a “-” meant “must exclude”. Nowadays, this no longer works. Now, you can of course go to the advanced search page, but most of us don’t do that. We type things into the browser’s URL bar and it dispatches to our favorite search provider… which in my case is Google. I figured there must be a nice way to bypass the middleman, and… there is! When you use the Advanced Search it actually just constructs a query, and we can do it ourselves with a small proxy script.
This example is using Ruby, but you could rig up something just as easily in python or node. I’m just most familiar with ruby so this was the fastest route to victory.
The query syntax we are targeting:
q: This is the query string. E.g.,
q=python
as_q: This is where you put words that must appear in the results. Equivalent to the old
+
syntax. E.g.,as_q=programming
as_epq: For exact phrases. E.g.,
as_epq="programming language"
as_oq: At least one of the words must appear. E.g.,
as_oq=("ruby" "python")
as_eq: Words to exclude. Equivalent to the old
-
syntax. E.g.,as_eq=snake
lr: Language restrict, like
lr=lang_en
as_filetype: To search for a specific file type. E.g.,
as_filetype=pdf
The Goal
When I type something in the URL bar, have it parse the query in the ‘old google syntax’ into a new query using those parameters.
For this simple example we’ll only implement the quotes and the ‘-’ minus operator, but you get the idea.
Steps
Create a script, something like `search_proxy.rb`
require 'webrick' require 'uri' require 'cgi' server = WEBrick::HTTPServer.new(Port: 8089) server.mount_proc '/' do |req, res| query_string = URI.parse(req.request_line.split[1]).query query_params = CGI.parse(query_string) raw_search = query_params["search"]&.first || "" q_param = [] epq_param = [] eq_param = [] in_quotes = false current_phrase = "" raw_search.split.each do |word| if word.start_with?('"') && word.end_with?('"') epq_param << word.gsub(/"/, '') elsif word.start_with?('"') in_quotes = true current_phrase = word.gsub(/"/, '') elsif word.end_with?('"') in_quotes = false current_phrase += " #{word.gsub(/"/, '')}" epq_param << current_phrase current_phrase = "" elsif in_quotes current_phrase += " #{word}" elsif word.start_with?('-') eq_param << word[1..-1] else q_param << word end end google_url = "https://www.google.com/search?" google_url += "q=#{q_param.join('+')}" unless q_param.empty? google_url += "&as_epq=#{URI.escape(epq_param.join(' '))}" unless epq_param.empty? google_url += "&as_eq=#{eq_param.join('+')}" unless eq_param.empty? res.set_redirect WEBrick::HTTPStatus::TemporaryRedirect, google_url end trap('INT') { server.shutdown } server.start
Add a new search provider to your browser
Start your script running
ruby search_proxy.rb
Set your new search provider as the default
Profit!
Enjoy! Drop me a comment if you like this.