mirror of
https://github.com/Ranchero-Software/NetNewsWire.git
synced 2025-02-02 03:56:55 +01:00
Add author information to indexed body
- Restore old code for database model - Modified `bodyForIndex` function to return `authorsNames` in it
This commit is contained in:
parent
6903db357a
commit
b4e150044b
@ -63,7 +63,6 @@ public final class ArticlesDatabase {
|
||||
}
|
||||
|
||||
private let articlesTable: ArticlesTable
|
||||
private let searchTable: SearchTable
|
||||
private let queue: DatabaseQueue
|
||||
private let operationQueue = MainThreadOperationQueue()
|
||||
private let retentionStyle: RetentionStyle
|
||||
@ -72,11 +71,9 @@ public final class ArticlesDatabase {
|
||||
let queue = DatabaseQueue(databasePath: databaseFilePath)
|
||||
self.queue = queue
|
||||
self.articlesTable = ArticlesTable(name: DatabaseTableName.articles, accountID: accountID, queue: queue, retentionStyle: retentionStyle)
|
||||
self.searchTable = SearchTable(queue: queue, articlesTable: self.articlesTable)
|
||||
self.retentionStyle = retentionStyle
|
||||
|
||||
try! queue.runCreateStatements(ArticlesDatabase.tableCreationStatements)
|
||||
try! queue.runCreateStatements(ArticlesDatabase.searchTableCreationStatements)
|
||||
queue.runInDatabase { databaseResult in
|
||||
let database = databaseResult.database!
|
||||
if !self.articlesTable.containsColumn("searchRowID", in: database) {
|
||||
@ -84,10 +81,6 @@ public final class ArticlesDatabase {
|
||||
}
|
||||
database.executeStatements("CREATE INDEX if not EXISTS articles_searchRowID on articles(searchRowID);")
|
||||
database.executeStatements("DROP TABLE if EXISTS tags;DROP INDEX if EXISTS tags_tagName_index;DROP INDEX if EXISTS articles_feedID_index;DROP INDEX if EXISTS statuses_read_index;DROP TABLE if EXISTS attachments;DROP TABLE if EXISTS attachmentsLookup;")
|
||||
if !self.searchTable.containsColumn("authors", in: database) {
|
||||
database.executeStatements("DROP TABLE if EXISTS search;")
|
||||
database.executeStatements(ArticlesDatabase.searchTableCreationStatements)
|
||||
}
|
||||
}
|
||||
|
||||
DispatchQueue.main.async {
|
||||
@ -338,14 +331,12 @@ private extension ArticlesDatabase {
|
||||
CREATE INDEX if not EXISTS articles_feedID_datePublished_articleID on articles (feedID, datePublished, articleID);
|
||||
|
||||
CREATE INDEX if not EXISTS statuses_starred_index on statuses (starred);
|
||||
|
||||
CREATE VIRTUAL TABLE if not EXISTS search using fts4(title, body);
|
||||
|
||||
CREATE TRIGGER if not EXISTS articles_after_delete_trigger_delete_search_text after delete on articles begin delete from search where rowid = OLD.searchRowID; end;
|
||||
"""
|
||||
|
||||
static let searchTableCreationStatements = """
|
||||
CREATE VIRTUAL TABLE if not EXISTS search using fts4(title, body, authors);
|
||||
|
||||
CREATE TRIGGER if not EXISTS articles_after_delete_trigger_delete_search_text after delete on articles begin delete from search where rowid = OLD.searchRowID; end;
|
||||
"""
|
||||
|
||||
func todayCutoffDate() -> Date {
|
||||
// 24 hours previous. This is used by the Today smart feed, which should not actually empty out at midnight.
|
||||
return Date(timeIntervalSinceNow: -(60 * 60 * 24)) // This does not need to be more precise.
|
||||
|
@ -35,7 +35,13 @@ final class ArticleSearchInfo: Hashable {
|
||||
|
||||
lazy var bodyForIndex: String = {
|
||||
let s = preferredText.rsparser_stringByDecodingHTMLEntities()
|
||||
return s.strippingHTML().collapsingWhitespace
|
||||
let sanitizedBody = s.strippingHTML().collapsingWhitespace
|
||||
|
||||
if let authorsNames = authorsNames {
|
||||
return sanitizedBody.appending(" \(authorsNames)")
|
||||
} else {
|
||||
return sanitizedBody
|
||||
}
|
||||
}()
|
||||
|
||||
init(articleID: String, title: String?, authorsNames: String?, contentHTML: String?, contentText: String?, summary: String?, searchRowID: Int?) {
|
||||
@ -49,7 +55,7 @@ final class ArticleSearchInfo: Hashable {
|
||||
}
|
||||
|
||||
convenience init(article: Article) {
|
||||
let authorsNames = article.authors?.map({ $0.name }).reduce("", { $0.appending("").appending($1 ?? "") })
|
||||
let authorsNames = article.authors?.map({ $0.name }).reduce("", { $0.appending("").appending($1 ?? "") }).collapsingWhitespace
|
||||
self.init(articleID: article.articleID, title: article.title, authorsNames: authorsNames, contentHTML: article.contentHTML, contentText: article.contentText, summary: article.summary, searchRowID: nil)
|
||||
}
|
||||
|
||||
@ -130,7 +136,7 @@ private extension SearchTable {
|
||||
}
|
||||
|
||||
func insert(_ article: ArticleSearchInfo, _ database: FMDatabase) -> Int {
|
||||
let rowDictionary: DatabaseDictionary = [DatabaseKey.body: article.bodyForIndex, DatabaseKey.title: article.title ?? "", DatabaseKey.authors: article.authorsNames ?? ""]
|
||||
let rowDictionary: DatabaseDictionary = [DatabaseKey.body: article.bodyForIndex, DatabaseKey.title: article.title ?? ""]
|
||||
insertRow(rowDictionary, insertType: .normal, in: database)
|
||||
return Int(database.lastInsertRowId())
|
||||
}
|
||||
@ -204,7 +210,7 @@ private extension SearchTable {
|
||||
return nil
|
||||
}
|
||||
let placeholders = NSString.rs_SQLValueList(withPlaceholders: UInt(searchRowIDs.count))!
|
||||
let sql = "select rowid, title, body, authors from \(name) where rowid in \(placeholders);"
|
||||
let sql = "select rowid, title, body from \(name) where rowid in \(placeholders);"
|
||||
guard let resultSet = database.executeQuery(sql, withArgumentsIn: searchRowIDs) else {
|
||||
return nil
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user