Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在使用 Spotlight API 在我的应用程序中提供搜索。我需要知道搜索字符串出现在文件中的次数,以便我可以实现排序描述符并对结果进行排序。有什么方法可以做到这一点而不必打开每个文件?Lucene 等其他库提供了非常有用的相关性评级。
您可以向元数据查询结果项询问NSMetadataQueryResultContentRelevanceAttribute键的值。
NSMetadataQueryResultContentRelevanceAttribute
这将返回NSNumber一个浮点值介于 0.0 和 1.0 之间的对象。
NSNumber
相关性值表示结果对象的内容的相关性。
您无法访问字符串在每个搜索结果中出现的实际次数。