Tricky behavior of attribute names in CSSearchQuery, can't find documentation

I am wanting to not only surface my content in the system-level Spotlight search results but also to utilize the same index for my in-app search screen. The very few examples or tutorials I could find all craft a CSSearchQuery string using just the "title" attribute. I can't figure out where to look to understand how to search across other attributes.

My most pressing need is to be able to perform a CSSearchQuery looking for a search term in the .htmlContentData attribute. If I search for this term in the system search field it returns results, so I know it's being indexed. However when I use a search query (in my app) like htmlContentData == "someSearchTerm" I get zero results.

This frustration has led to some more general questions like: How do you know what attribute names are available to use in the search query? Is it just a string literal that's exactly the same as the CSSearchableItemAttributeSet property in Swift? e.g. property .htmlContentData is referred to as "htmlContentData" in the query string?

Also, is there any way to just search across all attributes with CSSearchQuery? Obviously using the system Spotlight search (from Home Screen) you don't have to specify if you're searching the title or htmlContentData, it just finds it in either. Yet for CSSearchQuery I have to know up-front which fields I want to look in?

Replies

I may have found a solution to my most pressing issue but I think it only reinforces my other questions. Out of desperation I clicked through to see the generated headers for CSSearchableItemAttributeSet and, unlike the documentation which is in alphabetical order, the header has .htmlContentData and .textContent right next to each other. That gave me the idea to try a query string of textContent == "someSearchTerm" and now it seems to work! Although I'm grateful for this, it raises more questions for me because I only assign to .htmlContentData but yet I have to query "textContent". How can I figure this out in the future without blindly guessing?