Skip to content

Commit

Permalink
favor recent tags in autocomplete
Browse files Browse the repository at this point in the history
  • Loading branch information
PalmerAL committed Mar 14, 2020
1 parent 6624c89 commit fb97278
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions js/places/tagIndex.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ var tagIndex = {
termTags: {},
tagTagMap: {},
tagCounts: {},
tagUpdateTimes: {},
getPageTokens: function (page) {
var urlChunk = ''
try {
Expand Down Expand Up @@ -68,6 +69,12 @@ var tagIndex = {
}
})
})

page.tags.forEach(function (tag) {
if (!tagIndex.tagUpdateTimes[tag] || page.lastVisit > tagIndex.tagUpdateTimes[tag]) {
tagIndex.tagUpdateTimes[tag] = page.lastVisit
}
})
},
removePage: function (page) {
if (page.tags.length === 0) {
Expand Down Expand Up @@ -183,6 +190,10 @@ var tagIndex = {
score = 0
}
})

// prefer tags with a recently-visited (or created) page
score *= Math.max(2 - ((Date.now() - tagIndex.tagUpdateTimes[tag]) / (14 * 24 * 60 * 60 * 1000)), 1)

tagScores.push({tag, score})
}

Expand Down

0 comments on commit fb97278

Please sign in to comment.