Materials in the library's catalog are assigned controlled subject terms, usually from Library of Congress Subject Headings, to define precisely what the work is about.
While there are easily over a hundred LC Subject Headings relevant to LGBTQIA+ topics, most of them include common words, and so we can instead search just for works that include any of 20 different terms.
You can find more details on the linked "Subject terms" page.