Change S._build_query() to S.build_search()

* make _build_query public (and change the name)
* add to_json utility function
* add tests for to_json
* add documentation for utility functions

r?