I have an ObservableCollection, which holds a Person
object. I have a search feature in my application, and would like to display the most relevant results at the top. What would be the most efficient way of doing this? My current search method simply calls the contains
method:
var results = (from s in userList
where s.Name.Contains(query)
select s).ToList();
This works fine, but the results are ordered in the same order they appear within userList
. If I search for Pete
, then it should first display Pete
, then Peter
then Peter Smith
etc..
It doesn't have to be too complicated as it will only be dealing with a couple thousand (max) results. My naive approach was to first do s.Name == query
, display that item (if any), then perform the s.Name.Contains(query)
, remove the matched item and append it to the previous matched result. However, this seems a bit all over the place and so is there a better way? thanks
(ps - only the name will be used in searching, and I can't use SQL methods)