Looking up documents and updating their PageRank score

If we know a document's link ID, we can invoke the FindByID method to look up the indexed document. The implementation is pretty straightforward; we just acquire a read lock and lookup for the specified ID in the internal map maintained by the indexer. If a matching entry exists, we create a copy and return it to the caller:

You may be wondering why the FindByID implementation converts the input UUID into a string and delegates the actual document look up to the unexported findByID method. In the previous section, we saw that when we request bleve to index a document, we need to provide a string-based ID for the document. Bleve will return that ID to us when the document is matched by a search query. As will become evident in the following section, by providing a findByID method that accepts the linkID as a string, we can reuse the document lookup code when iterating search results.

To update the PageRank score for an existing document, clients invoke the UpdateScore method, which expects a document's link ID and the updated PageRank score:

Updating any searchable document attribute requires a reindex operation. Consequently, the UpdateScore implementation will acquire a write lock and look up the document in the internal document map. If the document is found, its PageRank score will be updated in-place and the document will be passed to bleve for indexing.