textmate 的“转到文件”是什么?模糊搜索算法?
Textmate 的“转到文件”模糊搜索真的很棒。
Wincent 的 vim Command-T 插件做了类似的事情,而且也很棒。
有人可以解释这些是如何工作的吗?他们使用的方法有通用术语吗?
编辑:关于这些工具的用途,我不太详细。
这些工具可以让您在键入时缩小选项列表(在本例中为文件路径)。
例如,如果我有以下文件:
/app/models/people.rb
/app/models/address.rb
/app/person.rb
/person.rb
要将列表缩小到 /app/models/people.rb
我可以输入以下任何内容:
amp
peo
mp
modelsp
它非常灵活,我发现自己缺少这个'当我使用的应用程序没有列表缩小功能时。我想了解更多相关信息,以便在需要时可以实现自己的插件。希望我能更好地解释它,但这就是我在这里的原因:)
要查看它的实际效果,请查看 wincent 的 command-t 演示
Textmate's 'go to file' fuzzy search is really awesome.
Wincent's Command-T plugin for vim does something similar and it rocks too.
Can someone explain how these work? Is there a general term for the method they use?
Edit: I little more detail about what those tools do
The tools let you narrow a list of options (in this case file paths) as you type.
For example if I had the following files:
/app/models/people.rb
/app/models/address.rb
/app/person.rb
/person.rb
to get to narrow the list to /app/models/people.rb
I could type any of the following:
amp
peo
mp
modelsp
it's very flexible and I find my self missing this 'list narrowing' when the app I'm using doesn't have it. I'd like to learn more about it so that I may implement my own plugins if I ever felt the need. Wish I could explain it better, but that's why I'm here :)
To see it in action take a look at wincent's demo of command-t
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
它似乎在每个字母之间进行通配符搜索。
如果它仅匹配选项列表中的一项,那么它将返回该项目作为预期选项。
It appears to be doing a wildcard search between every letter.
If it matches only one item in the list of options, then it would return that as the intended option.
看起来 Command-T 根据
match.c
中的recursive_match
函数给出的double
分数进行排序,以进行模糊搜索。 Command-T 的源代码受作者版权所有,但可以通过在文本编辑器中打开 vimball 找到源代码(在 此页面),并且可能可以用作更通用的模糊搜索算法的灵感(至少比我读 C 语言更好的人)。It looks like Command-T does a sort based on a
double
score given by therecursive_match
function inmatch.c
to do the fuzzy search. Command-T's source is copyrighted by the author but the source can be found by opening the vimball in a text editor (download at the bottom of this page), and could probably be used as inspiration for a more general fuzzy search algorithm (by somebody who reads C better than me at least).看起来这就是您正在谈论的确切代码:
https://github.com/textmate/textmate/blob/master/Frameworks/text/src/ranker.cc
Looks like this is the exact code you're talking about:
https://github.com/textmate/textmate/blob/master/Frameworks/text/src/ranker.cc
不知道这是如何工作的,但是为了快速查找,您可以生成类似于 http://en.wikipedia 的内容。 org/wiki/Directed_acirclic_word_graph 并具有 O(L) 复杂度,其中 L 是搜索模式的长度。
Have no idea how this works, but for fast lookups you can generate something similar to http://en.wikipedia.org/wiki/Directed_acyclic_word_graph and have O(L) complexity, where L is length of search pattern.
作为旁注:看看 (Apache Solr) 及其生成索引的方式。当我尝试在网络上实现类似于 Textmate 的 Command-T 的功能时,我发现自己经常使用它。
具体请查看 EdgeNGramFilterFactory。我相信某处甚至可能有一些源代码。 (虽然它是用Java编写的......)
As a sidenote: Take a look at (Apache Solr) and the way it generates indexes. I find myself using it quite a bit when I am trying to implement something similar to Textmate's Command-T on the web.
Specifically check out the EdgeNGramFilterFactory. I believe there might even be some sourcecode somewhere. (It's in Java though…)