Or just have two text inputs[1]: one for url and one for search, rather than trying to overload two functions into one text input and trying to guess what the user wants.
[1] https://support.mozilla.org/en-US/kb/add-search-bar-firefox-...
[1] https://support.mozilla.org/en-US/kb/add-search-bar-firefox-...