Skip to content

Commit

Permalink
(fix) return topN when query and current are both empty.
Browse files Browse the repository at this point in the history
refs #14
  • Loading branch information
raghur committed Oct 18, 2018
1 parent 30e6220 commit 3931fb6
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
13 changes: 10 additions & 3 deletions rplugin/fruzzy_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,20 @@
from python3.fruzzy import scoreMatches


def scoreMatchesProxy(q, c, limit, key=None, ispath=True):
def scoreMatchesProxy(q, c, limit=10, current="", key=None, ispath=True):
def idfn(x):
return x
if key is None:
key = idfn
if useNative:
idxArr = scoreMatchesStr(q, [key(x) for x in c],
"", limit, ispath)
current, limit, ispath)
results = []
for i in idxArr:
results.append((c[i[0]], i[1]))
return results
else:
return scoreMatches(q, c, "", limit, key, ispath)
return scoreMatches(q, c, current, limit, key, ispath)


lines = []
Expand Down Expand Up @@ -129,3 +129,10 @@ def test_for_bug_08():
results = list(scoreMatchesProxy("fmf", c, 10, ispath=True))
assert results[0][0] == \
'rplugin/python3/denite/filter/matcher/fruzzymatcher.py'

def test_must_return_topN_when_query_and_current_are_empty():
c = ["/this/is/fileone.txt", "/that/was/FileOne.txt"]
results = list(scoreMatchesProxy("", c, 10, ispath=False))
assert len(results) == 2
assert results[0][0] == c[0]
assert results[1][0] == c[1]
17 changes: 11 additions & 6 deletions rplugin/python3/fruzzy_mod.nim
Original file line number Diff line number Diff line change
Expand Up @@ -300,15 +300,20 @@ iterator fuzzyMatches(query:string, candidates: openarray[string], current: stri
heap.push((i, rank))
if findFirstN and count == limit * 5:
break
else: # if blank string just take N items based on levenshtien (rev)
elif query == "" and current != "" and ispath: # if query is empty just take N items based on levenshtien (rev)
for i, x in candidates:
if current != x:
heap.push((i, 300 - current.editDistance(x)))
count = 0
while count < limit and heap.size > 0:
let item = heap.pop
yield item
count.inc
else: # just return top N items from candidates as is
for j in 0 ..< min(limit, candidates.len):
yield (j, 0)

if heap.size > 0:
count = 0
while count < limit and heap.size > 0:
let item = heap.pop
yield item
count.inc

proc scoreMatchesStr(query: string, candidates: openarray[string], current: string, limit: int, ispath:bool=true): seq[tuple[i:int, r:int]] {.exportpy.} =
result = newSeq[tuple[i:int, r:int]](limit)
Expand Down

0 comments on commit 3931fb6

Please sign in to comment.