High performance “contains” search in list of strings in C#

前端 未结 7 1604
情话喂你
情话喂你 2020-12-05 07:54

I have a list of approx. 500,000 strings, each approx. 100 characters long. Given a search term, I want to identify all strings in the list that contain the search term. At

7条回答
  •  时光取名叫无心
    2020-12-05 08:39

    I've heard good things about Lucene.NET when it comes to performing quick full-text searches. They've done the work to figure out the fastest data structures and such to use. I'd suggest giving that a shot.

    Otherwise, you might just try something like this:

    var matches = list.AsParallel().Where(s => s.Contains(searchTerm)).ToList();
    

    But it probably won't get you down to 100ms.

提交回复
热议问题