Core Data & Core Spotlight on macOS

I'm struggling a bit with a couple of aspects of this.


I seem to have the basics working. I can launch my application, make an edit to a core data record, search for it in Spotlight, and it shows up. I can click on the result and end up back in my app highlighting the relevant record.


All good.


However, I'm struggling with a couple of problems.


1. I want to offer the user a plain-text search within the application. I can see how to set up the search query, but it seems to need to be of the form "<attribute> <operator> <value>" - eg "name == 'test'".


I don't want to have to specify an attribute - I want to do a free-text search that will pick up any attribute (just like typing into the system Spotlight search field).


Any idea how I achieve this?



2. My application has an option to start with some sample data. This actually comes from a pre-build database, which I swap in using `replacePersistentStore`. Whatever I do, I can't seem to get core spotlight to index this data. The WWDC session said that it'll do a full index when it first encounters some new data. This does not seem to happen. I'm not clear if i'm supposed to be doing something to prompt this to happen. There are other ways that I could generate the sample data if necessary, but it's very convenient being able to just swap in an existing database.


Any thoughts on how to achieve this?

Replies