[deleted]
Indexing today is mostly done with special indexing software and/or a database. It is, however still necessary to read through the whole book and be careful about what you index (e.g. "She was beautiful as Cleopatra" would not be indexed under Cleopatra)
Indexing appeared after the printing press and the process worked exactly as you would imagine it. A galley proof was produced, somebody read through it, noted what belonged where in the index and then the end product was printed. So, even if a book had a thousand pages, someone (in earlier times the author, today mostly a contractor or someone employed by the publishing company)reads through the whole thing and notes what goes where in the index.
Btw. one of the first indexes in the modern sense dates back to Sir Thomas North's 1595 translation of Plutarch's Parallel Lives.
Sources.:
Hans Wellisch, Indexing from A to Z, H.W. Wilson Co., 1991.
Knight, G. Norman, Indexing, the Art of: A Guide to the Indexing of Books and Periodicals, HarperCollins, 1979.