From 5806c179b701df4cb493c4248737722bd9de8ab6 Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Sat, 25 Jul 2020 18:58:05 -0700 Subject: [PATCH] Add indexing functions to SearchTable. --- Frameworks/ArticlesDatabase/SearchTable.swift | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/Frameworks/ArticlesDatabase/SearchTable.swift b/Frameworks/ArticlesDatabase/SearchTable.swift index 1b797d12a..10fe34c5d 100644 --- a/Frameworks/ArticlesDatabase/SearchTable.swift +++ b/Frameworks/ArticlesDatabase/SearchTable.swift @@ -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
, _ database: FMDatabase) { + let articleSearchInfos = Set(articles.map{ ArticleSearchInfo(article: $0) }) + performInitialIndexForArticles(articleSearchInfos, database) + } + + /// Index updated articles. + func indexUpdatedArticles(_ articles: Set
, _ database: FMDatabase) { + ensureIndexedArticles(articles.articleIDs(), database) + } } // MARK: - Private