如何实现清单上渐进式搜索 [英] How to implement incremental search on a list

查看:324
本文介绍了如何实现清单上渐进式搜索的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想实现一个字符串列表上的渐进式搜索。想想我有一个包含一个数组,它包含字符串存储,状态,印花税,爬行,乌鸦。我的应用程序具有将用户输入的搜索字符串的文本框。现在,当用户输入的文字,我需要强调所有的比赛。例如,当用户输入ST我需要强调商店,州,邮票现在,当他类型一,我需要从list.I删除商店正在开发使用C#在.NET应用程序框架。我打算做的是,在事件上的文字变化,我在后台搜索并显示结果。有没有解决这个其他方式?

I want to implement incremental search on a list of strings. Consider I have an array containing which contains the strings store,state,stamp,crawl,crow. My application has a text box in which the user enters the search string. Now, as the user enters the text, I need to highlight all the matches. For example, when the user enters "st" I need to highlight "Store,state,stamp" now when he types "a", I need to remove "Store" from the list.I am developing the application using c# with .net framework. What I plan to do is , on event on which text changes, I do a search in background and show the results. Is there any other way to solve this ?

推荐答案

您可以只看看新进入的信;如果新的第三个字母是A刚抛出的所有元素,而A在三个位置上。如果用户删除了一封信,你必须重新扫描整个原始清单,并带回所有priviously删除的项目。

You could just look at the newly entered letter; if the new third letter is an 'a' just throw out all elements without 'a' at position three. If the user deletes a letter you have to rescan the whole original list and bring back all priviously removed items.

但是,如果用户从剪贴板粘贴多个字母,通过选择,插入删除多个字母或中间的某个位置删除单个或多个信吗?

But what if the user pastes multiple letters from the clipboard, deletes multiple letters by selecting them, inserts or deletes a single or multiple letters somewhere in the middle?

您刚才很多情况下观看的。你可以用新输入的字母执行方法的回落到一个完整的重新扫描,如果在搜索文本的方式不是增加一个字母等改变,但即使这样简单的方法可能是不值得的,只是为了避免几十年,百字符串比较。如已经提到的,一个 Trie树帕特里夏线索是要走的路,如果你有真正的大数据集或想成为非常快。

You have just to many cases to watch for. You could do the method with the newly entered letter an fall back to a complete rescan if the search text changed in a way other than adding a single letter, but even this simple method is probably not worth the effort just to avoid a few ten or hundred string comparisons. As already mentioned, a Trie or Patricia trie is the way to go if you have really large data sets or want to be really quick.

这篇关于如何实现清单上渐进式搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆