Add indexing functions to SearchTable.

This commit is contained in:
Brent Simmons
2020-07-25 18:58:05 -07:00
parent b92a58144f
commit 5806c179b7

View File

@@ -45,6 +45,10 @@ final class ArticleSearchInfo: Hashable {
self.searchRowID = searchRowID
}
convenience init(article: Article) {
self.init(articleID: article.articleID, title: article.title, contentHTML: article.contentHTML, contentText: article.contentText, summary: article.summary, searchRowID: nil)
}
// MARK: Hashable
public func hash(into hasher: inout Hasher) {
@@ -93,6 +97,17 @@ final class SearchTable: DatabaseTable {
let indexedArticles = articleSearchInfos.filter { $0.searchRowID != nil }
updateIndexForArticles(indexedArticles, database)
}
/// Index new articles.
func indexNewArticles(_ articles: Set<Article>, _ database: FMDatabase) {
let articleSearchInfos = Set(articles.map{ ArticleSearchInfo(article: $0) })
performInitialIndexForArticles(articleSearchInfos, database)
}
/// Index updated articles.
func indexUpdatedArticles(_ articles: Set<Article>, _ database: FMDatabase) {
ensureIndexedArticles(articles.articleIDs(), database)
}
}
// MARK: - Private