Add optgroup search feature as an option

Cherry-picked the commit from the `search_improvements` branch and offer an option to disable this if the new behavior is undesirable.
However, I think it should be turned on by default, and left it that way. Feel free to discuss about that.

Fixes #298 and its duplicates: #432, #538.