There is no “CatalogSet.getMasterKeywords()”. It’s a typo in the NP API section of the manual, one of many that’s been (re-)reported in every version of the manual since launch (v7)! Despite being given a detailed correction list the manual’s author has persistently refusing to correct the NP API’s many typos, for reasons I can’t fathom. Not fixing it leads to problems like you’ve hit. Also note that the record object (case-sensitive) is ‘record’ with a lowercase ‘r’ and not Record as shown in the manual.
I believe from testing I did early on in NP’s life that “CatalogSet.getMasterKeywords()” should really be “CatalogSet.getMasterKeywordsAll()”. In fact you probably want it at Catalog object scope, though few users deploy sites pulling data from multiple catalogues - which is what CatalogSet is for.
Whatever, it won’t solve your problem as getMasterKeywordsAll() simply loads in the Master Keyword List (MKL) you see in the Portfolio client for that catalogue. Portfolio can’t tell you which MKL values are used and which aren’t. You’ll need to figure that out by some other means and store (only) the MKL’s used words as the predefined list (PDL) for a custom field. now you load the PDL instead of the MKL but target searches from that list to the Keywords field.
You get a PDL like this, assuming field "Used Keywords"has a PDL:
Not too intuitive, but I hope that helps. BTW, do report the bugs in the manual as perhaps its a popularity thing - typos only get fixed if more than N people complain.