Replacing wordpress search with custom code

Sorry about my english. I think you must use the build-in query hook to send your posts ids to the main query. It use the pre_get_posts hook. That will allow you to change the query after it’s creation, and before it’s execution.

add_action('pre_get_posts', 'my_search_query');
function my_search_query($query) {
    if($query->is_search() && $query->is_main_query() && get_query_var('s', false)) {   
        // Get the "s" query arg from the initial search
        $desired_query = get_query_var('s', false);

        // Your code
        $url="http://{SOLR_IP}:{SOLR_PORT}/solr/{CORE_NAME}/select?indent=on&q={ DESIRED_QUERY }&wt=json";
        $result = file_get_contents($url);
        $data = json_decode($result, true);

        $ids = array();
        foreach ($data['response']['docs'] as $item)
        {
            array_push($ids, $item['id']);          
        }

        // Update the main query
        $query->set('post__in' => $ids);
    }
    return $query;
}

You will update the main query with your new ids from your Solr system.
There is probably better ways to get the search query like using get_search_query but I’m not sure that this function is defined during pre_get_posts hook.