c# - Fastest way to search for contents of files -


i'm doing search specific text in web files. user enters text. there 850 files have search. code below accomplishes want takes 11-13 seconds. code in web service call web page using $.ajax get. there way can improve code search goes faster? or should looking @ other areas instead of code?

i replaces in document because of how files created (they create web files using ms word...another battle) , improves search results.

var searchresults = new stringbuilder();  var parameters = searchparameters.split('|');  var searchoncompletephrase = bool.parse(parameters[1]);  var completephrasepattern = @"\b(?:" + regex.escape(parameters[0].tostring()) + @")\b";  var files = directory.getfiles(path, "*.htm");  if (searchoncompletephrase && searchphrase.length > 1) {     foreach (var currentfile in files)     {         document.load(currentfile);          contents = document.documentnode.innertext.replace("\r", string.empty)             .replace("\n", string.empty)             .replace(" ", string.empty)             .replace("  ", " ");          if (contents.tolower().indexof(searchphrase.tolower()) > -1)         {             searchresults.appendline(currentfile);              searchresults.append("|");         }     } } else {     var keywords = parameters[0].split(' ');      foreach (var currentfile in files)     {         document.load(currentfile);          contents = document.documentnode.innertext.replace("\r", string.empty)             .replace("\n", string.empty)             .replace(" ", string.empty)             .replace("  ", " ");          var found = true;          foreach (var word in keywords)         {             if (!searchcurrentword(word.tostring()))             {                 found = false;                  break;             }         }          if (found)         {             searchresults.appendline(currentfile);              searchresults.append("|");         }     } } 

maybe should try parallel.foreach instead of foreach loop avoid waiting every file disk sequentially.


Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -