mirror of
https://github.com/pulsar-edit/pulsar.git
synced 2024-09-21 16:08:24 +03:00
parent
9a2e768882
commit
04373d2d9d
@ -1,4 +1,5 @@
|
||||
stringScore = require 'stringscore'
|
||||
path = require 'path'
|
||||
|
||||
module.exports = (candidates, query, options={}) ->
|
||||
if query
|
||||
@ -6,9 +7,13 @@ module.exports = (candidates, query, options={}) ->
|
||||
string = if options.key? then candidate[options.key] else candidate
|
||||
score = stringScore(string, query)
|
||||
|
||||
# Basename matches count for more.
|
||||
unless /\//.test(query)
|
||||
score += stringScore(string.replace(/^.*\//,''), query)
|
||||
# Basename matches count for more.
|
||||
score += stringScore(path.basename(string), query)
|
||||
|
||||
# Shallow files are scored higher
|
||||
depth = Math.min(1, 10 - string.split('/').length - 1)
|
||||
score *= depth * 0.01
|
||||
|
||||
{ candidate, score }
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user