views:

29

answers:

1

Alright so I've got a ListView with many items available to it any time (in virtualized mode). Right above the ListView is a text box that allows the user type in any search term and the ListView will be filtered live. The ListView is currently bound to a DataSet like this:

SoundListView.DataContext = DS.Tables[0].DefaultView;

The DataSet is being pulled from an internal SQLite database.

And here is the current filter code that takes the search box text to filter the ListView:

DS.Tables[0].DefaultView.RowFilter = String.Format("path LIKE '%{0}%'", EscapeLikeValue(SearchTextBox.Text));

You can see here I am using a crappy LIKE SQL modifier to filter my items based on the key term. This is bad because LIKE isn't a replacement for full-text search IMO. To solve this problem, I implemented Lucence.NET.

Using Lucene, I am taking the search term from the text box and it is performing a more Google-esque search, where I can use boolean operators and do fuzzy matching and cool things like that. This search is currently working! The Lucene search is returning a list of IDs that correspond to the IDs in the DataSet feeding the ListView.

So the last piece of my puzzle is getting these Lucene search hits to filter the ListView. Should I use RowFilter and concanenate all of the IDs that match in some horrible SQL line like:

... RowFilter = "id = 1 OR id = 3 OR id = 7"

Or is there a better way to do this?

A: 

You should use CollectionViewSource and it's Filter event to filter data in a collection. Use CollectionViewSource.GetDefaultView() method to get a default View.


Here is a reference to a Sort and Filter sample : http://go.microsoft.com/fwlink/?LinkID=160040 from this page.

decyclone
How do you efficiently pass a list of IDs into the Filter function?
Kirk
Updated the post!
decyclone