YaCy harvests web pages with a web crawler. Documents are then parsed, indexed and the search index is stored locally. If your peer is part a peer network, then your local search index is also merged into the shared index for that network. If a search is started then the local index contributes together with a global search index from peers in the YaCy search network.
YaCy peers continuously exchange index fragments using a Distributed Hash Table. Index data can therefore reach the local peer even before a user query is submitted, but of course it is still loaded from the remote peer network too when needed.