1
我需要按相关性对搜索结果进行排序,同时尝试解决Realm的NSPredicate限制。从领域查询排除对象 - 尝试按相关性排序(Swift)
我现在尝试重复的结果:
if searchText.characters.count > 0 {
//First search is attempting exact match
relevantResults = Array(dataModel.terms.filter("%K BEGINSWITH[c] %@", "title", searchText).sorted(byProperty: "title"))
//Appended Results are looking for 'close enough' but include results that were already in the first search
relevantResults.append(contentsOf: Array(dataModel.terms.filter("%K CONTAINS[c] %@", "title", searchText).sorted(byProperty: "title")))
} else {
relevantResults = Array()
}
我试图发挥创意与其他一些谓词过滤器,如:
"title NOT BEGINSWITH[c] %@ AND title CONTAINS[c] %@"
和
"SELF NOT IN %@"
它们要么不受Realm支持,或者不是有效的谓词过滤器。 无论哪种方式,我需要找到一个解决方案,按照相关性排序,无需重复。
在单独的TableView部分中会显示更多的搜索结果,我想排除“最佳匹配”结果。
我想避免循环从第一组结果中获取所有标题(如果可能的话),但似乎我可能不得不求助于此,除非有一些我不考虑的数组函数?有什么建议么?