Putting search query parsing logic into a separate function