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.
Asked
Active
Viewed 101 times
1 Answers
1
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.

Rob Keniger
- 45,830
- 6
- 101
- 134
-
I must add that you should ask for 'NSMetadataQueryResultContentRelevanceAttribute' from NSMetadataQuery and NOT the result item. – Bhargava Srinarasi May 08 '12 at 13:11