Question

I'm using Spotlight APIs to provide search in my application. I need to know the no of times the search string is present in a file so that I can implement a Sort Descriptor and sort the results. Is there any way to do this without having to open every file? Other libraries like Lucene give relevance rating which is very useful.

Was it helpful?

Solution

You can ask your metadata query result items for the value of the NSMetadataQueryResultContentRelevanceAttribute key.

This will return an NSNumber object with a floating point value between 0.0 and 1.0 inclusive.

The relevance value indicates the relevance of the content of the result object.

You can't access the actual number of times your string is present in each search result.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top