 
     
     /// Search the local mirror.
-    // TODO: Should be called from regular search
     public func searchMirror(query: Query, block: CompletionHandler) {
         let callingQueue = NSOperationQueue.currentQueue() ?? NSOperationQueue.mainQueue()
         self.offlineClient.searchQueue.addOperationWithBlock() {

        }
    }
    
    private func _searchMirror(query: Query, block: CompletionHandler) {
        assert(!NSThread.isMainThread()) // make sure it's run in the background
        assert(self.mirrored, "Mirroring not activated on this index")

        assert(content != nil || error != nil)
        block(content: content, error: error)
    }
    
    // ----------------------------------------------------------------------
    // Browse
    // ----------------------------------------------------------------------
    
    public func browseMirror(query: Query, block: CompletionHandler) {
        let callingQueue = NSOperationQueue.currentQueue() ?? NSOperationQueue.mainQueue()
        self.offlineClient.searchQueue.addOperationWithBlock() {
            self._browseMirror(query) {
                (content, error) -> Void in
                callingQueue.addOperationWithBlock() {
                    block(content: content, error: error)
                }
            }
        }
    }

    /// Browse the local mirror synchronously.
    private func _browseMirror(query: Query, block: CompletionHandler) {
        assert(!NSThread.isMainThread()) // make sure it's run in the background
        assert(self.mirrored, "Mirroring not activated on this index")
        
        var content: [String: AnyObject]?
        var error: NSError?
        
        let searchResults = localIndex!.browse(query.buildURL())
        // TODO: Factorize this code with above and with online requests.
        if searchResults.statusCode == 200 {
            assert(searchResults.data != nil)
            do {
                let json = try NSJSONSerialization.JSONObjectWithData(searchResults.data!, options: NSJSONReadingOptions(rawValue: 0))
                if json is [String: AnyObject] {
                    content = (json as! [String: AnyObject])
                } else {
                    error = NSError(domain: AlgoliaSearchErrorDomain, code: 500, userInfo: [NSLocalizedDescriptionKey: "Invalid JSON returned"])
                }
            } catch let _error as NSError {
                error = _error
            }
        } else {
            error = NSError(domain: AlgoliaSearchErrorDomain, code: Int(searchResults.statusCode), userInfo: nil)
        }
        assert(content != nil || error != nil)
        block(content: content, error: error)
    }

}
