views:

57

answers:

1

My site (ASP.NET + C#) has FAQ data pull from another site's web service in XML format. The data size is pretty small (just about 50 faqs). I want to implement a keyword search for the FAQ and highlight the search keyword. What could be a fast and easy approach to do this?

My first thought is just using a C# string search or any XML search method. I know this is not scalable. But consider the FAQ is little, it may not need to index the FAQ. I could be wrong. Can anyone give me some suggestions? Thanks.

+2  A: 

The best solution to this is using Regular Expressions. RegEx scales well too, so you don't need to worry that much about speed. Using RegEx Replace, adding a tag around the matches to make them stand out is easy as well.

You can find a good RegEx tutorial here. It has good info about both general RegEx use, and that link goes to their explanation about .NETs implementation.

RegEx has a step learning curve, but it is worth the effort, because it is incredibly powerful.

davisoa
@davisoa: thanks for the great idea. But if I want the search box can filter some words like "is, the",etc. And maybe some other basic functionality for search box.
Stan
I'm not sure I follow you - you want to exclude "is" and "the" from the matches?
davisoa
I want when there're is/the appears in the search term, they will be skipped since searching those keyword is meaningless.
Stan
In that case, I would just use `String.Split(' ')` to break up the keyword text, and then remove any instance of "is" or "the" in the resulting array. Then process each remaining member the array using a RegEx Replace against the FAQs.
davisoa