建议实现一个简单的搜索"业务对象"在.NET WinForms应用程序? [英] Suggestions for implementing a simple search for "business objects" in a .NET WinForms app?

查看:207
本文介绍了建议实现一个简单的搜索"业务对象"在.NET WinForms应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是去了解在.NET WinForms应用程序提供的业务对象一个简单的搜索功能最好的方法是什么?

What's the best way to go about providing a simple search capability for "business objects" in a .NET WinForms application?

通过简单搜索我的意思是喜欢Vista + Windows 7的搜索框这是几乎在每一个窗口的右上角的角落,可以搜索该窗口中的内容(没有什么花哨,大概没有先进进行搜索 - 保持简单)

By "simple search" I mean something like Vista + Windows 7's "search box" that's in the upper-right-hand corner of almost every window, that searches the contents of that window (nothing fancy, probably no "advanced" search either - keep it simple).

按业务对象我的意思是对象基于类的东西,如客户和地址(只是你简单的径流式的磨联络信息居多)。

By "business objects" I mean objects based on classes for things like "clients" and "addresses" (just your simple run-of-the-mill contact info mostly).

我认为我自己的滚动简单的搜索,也许有我的课实行包含功能,这样我可以问每一个对象是否包含任何用户的搜索字词(然后构建某种基于多少字简单的等级相匹配)。

I've considered "rolling my own" simple search, maybe having my classes implement a "Contains" function so that I can ask each object if it "contains" any of the user's search terms (and then build in some sort of simple rank based on how many words were matched).

我也看着Lucene.NET,但似乎对我的需要过于复杂 - 必须建立索引(和更新和维护)。

I've also looked into Lucene.NET, but it seems overly complex for my needs - having to build an index (and update and maintain it).

建议?想法?

推荐答案

我不知道最好的方式(我在谷歌工作,如果我这样做)。鉴于这种情况,不过,我并实现概念验证的/客户演示几个月前,这奏效了类似的事情。请注意,我是能够有效地约束问题域pretty的,尤其是在WRT立即搜索数据集的规模,使之性能不是问题。

I don't know about the "best" way (I'd work at Google if I did). Given that, though, I did implement something similar in a proof-of-concept/customer demo a few months back that did the trick. Note that I was able to constrain the problem domain pretty effectively, especially wrt the immediately searchable dataset's size, so that performance wasn't an issue.

我创建了一个 FilterableListView 用户控件 。我用了一个 的ListView 详情模式,我放弃了的 文本框 在其上方,并采用互操作平台,给它一定的 CueText (类似于过滤器或搜索)。然后我更新了的ListView 的内容从后台线程(用我的执行<一个相当于href="http://stackoverflow.com/questions/714666/is-it-appropriate-to-extend-control-to-provide-consistently-safe-invoke-begininvo/714680"><$c$c>SafeInvoke)如果有自上次 框TextChanged 从过滤箱的事件。

I created a FilterableListView UserControl. I used a ListView in Detail mode, I dropped a TextBox immediately above it and used platform interop to give it some CueText (something like "Filter" or "Search"). I then updated the contents of the ListView from a background thread (using the equivalent of my implementation of SafeInvoke) if there was a 0.5 second delay since the last TextChanged event from the filter box.

我做了一个简单的,不区分大小写的子对在的ListView 指定的字段的内容匹配,这是快速,简单,有效。我发现LINQ到对象进行的非常的是有用的。

I did a simple, case-insensitive substring match against the contents of a specified field in the ListView, it was quick, simple, and effective. I found Linq to Objects to be very useful.

这几件事情我会为更多的生产准备实施做的更好:

A few things I would have done better for a more production-ready implementation:

  1. 使用双击速度在进行搜索之前计算出一个适当的延迟。
  2. 提供一个回调机制来执行它建设成为控制的搜索代替。也许类似的 IFilterable 接口?
  1. Use the double click speed to calculate an appropriate delay before performing the search.
  2. Provide a callback mechanism to perform the search instead of building it into the control. Perhaps something like an IFilterable interface?

这篇关于建议实现一个简单的搜索&QUOT;业务对象&QUOT;在.NET WinForms应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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