Autocomplete: higher scores for full hostnames
This commit is contained in:
@@ -53,7 +53,8 @@ class BrowserHistory
|
||||
|
||||
let fetchRequest: NSFetchRequest<HistoryItemEntity> = HistoryItemEntity.fetchRequest()
|
||||
fetchRequest.predicate = NSPredicate(format: "host CONTAINS %@ OR title contains %@", matching, matching)
|
||||
fetchRequest.fetchLimit = 100
|
||||
fetchRequest.fetchLimit = 200
|
||||
fetchRequest.sortDescriptors = [ NSSortDescriptor(key: "visitCount", ascending: false) ]
|
||||
|
||||
let entities: [HistoryItemEntity] = (try? dataContext.fetch(fetchRequest)) ?? []
|
||||
let allItems: [HistoryItem] = entities.map { HistoryItem(entity: $0) }
|
||||
@@ -61,13 +62,15 @@ class BrowserHistory
|
||||
var topLevelItems: [URL: (HistoryItem, Int)] = [:]
|
||||
for item in allItems {
|
||||
if item.url.pathComponents.count <= 2 {
|
||||
var score = 1
|
||||
let topLevelURL = item.url.topLevelURL()
|
||||
var topLevelItem = topLevelItems[topLevelURL] ?? (item, 0)
|
||||
topLevelItem.0.url = topLevelURL
|
||||
if item.url.path == "/" || item.url.path == "" {
|
||||
score += 10
|
||||
topLevelItem.0.title = item.title
|
||||
}
|
||||
topLevelItem.1 += 1
|
||||
topLevelItem.1 += score
|
||||
topLevelItems[topLevelURL] = topLevelItem
|
||||
|
||||
if topLevelItems.count == 20 {
|
||||
|
||||
Reference in New Issue
Block a user