lib/easydoc.js
function search(searched, callback) {
		var root = pathUtils.resolve(options.root);
		// search command is platform dependant: use grep on linux, and findstr on windaube.
		var command = os.platform() === 'win32' ? 
			'findstr /spin /c:"'+searched+'" '+ pathUtils.join(root, '*.*') :
			'grep -rin "'+searched+'" '+root;

		// exec the command line.
		exec(command, function (err, stdout, stderr) {
			if (err) {
				// a 1 error code means no results.
				if (err.code === 1) {
					err = null;
				}
				return callback(err, []);
			}
			// each line an occurence.
			var lines = stdout.toString().split(root);
		  // remove files that are not markdown.
		  lines = _.filter(lines, function(val) {
		  	return val.trim().length > 0;
		  });
	    // regroups by files
	    var grouped = {};
	    for(var i = 0; i < lines.length; i++) {
	    	var numStart = lines[i].indexOf(':');
	    	var numEnd = lines[i].indexOf(':', numStart+1);
	    	
	    	// remove leading \
	    	var fileName = lines[i].substring(1, numStart);
	    	// ignore assets files
	    	if (/^_assets/.test(fileName)) {
	    		continue
	    	}
	    	if (!(fileName in grouped)) {
	    		grouped[fileName] = [];
	    	}
	    	grouped[fileName].push({hit:lines[i].substring(numEnd+1).replace(new RegExp(searched, 'gi'), '<b>$&</b>')});
	    }
	    // sort by relevance
	    var files = [];
	    for(var key in grouped) {
	    	files.push({
	    		path: key, 
	    		hits: grouped[key]
	    	});
	    }
	    callback(null, files.sort(function(a, b) {
	    	return b.hits.length - a.hits.length;
	    }));
	  });
	}
function search(searched, callback) {
		var root = pathUtils.resolve(options.root);
		// search command is platform dependant: use grep on linux, and findstr on windaube.
		var command = os.platform() === 'win32' ? 
			'findstr /spin /c:"'+searched+'" '+ pathUtils.join(root, '*.*') :
			'grep -rin "'+searched+'" '+root;

		// exec the command line.
		exec(command, function (err, stdout, stderr) {
			if (err) {
				// a 1 error code means no results.
				if (err.code === 1) {
					err = null;
				}
				return callback(err, []);
			}
			// each line an occurence.
			var lines = stdout.toString().split(root);
		  // remove files that are not markdown.
		  lines = _.filter(lines, function(val) {
		  	return val.trim().length > 0;
		  });
	    // regroups by files
	    var grouped = {};
	    for(var i = 0; i < lines.length; i++) {
	    	var numStart = lines[i].indexOf(':');
	    	var numEnd = lines[i].indexOf(':', numStart+1);
	    	
	    	// remove leading \
	    	var fileName = lines[i].substring(1, numStart);
	    	// ignore assets files
	    	if (/^_assets/.test(fileName)) {
	    		continue
	    	}
	    	if (!(fileName in grouped)) {
	    		grouped[fileName] = [];
	    	}
	    	grouped[fileName].push({hit:lines[i].substring(numEnd+1).replace(new RegExp(searched, 'gi'), '<b>$&</b>')});
	    }
	    // sort by relevance
	    var files = [];
	    for(var key in grouped) {
	    	files.push({
	    		path: key, 
	    		hits: grouped[key]
	    	});
	    }
	    callback(null, files.sort(function(a, b) {
	    	return b.hits.length - a.hits.length;
	    }));
	  });
	}
function search ( searched , callback ) { var root = pathUtils . resolve ( options . root ) ; // search command is platform dependant: use grep on linux, and findstr on windaube. var command = os . platform ( ) === 'win32' ? 'findstr /spin /c:"' + searched + '" ' + pathUtils . join ( root , '*.*' ) : 'grep -rin "' + searched + '" ' + root ; // exec the command line. exec ( command , function ( err , stdout , stderr ) { if ( err ) { // a 1 error code means no results. if ( err . code === 1 ) { err = null ; } return callback ( err , [ ] ) ; } // each line an occurence. var lines = stdout . toString ( ) . split ( root ) ; // remove files that are not markdown. lines = _ . filter ( lines , function ( val ) { return val . trim ( ) . length > 0 ; } ) ; // regroups by files var grouped = { } ; for ( var i = 0 ; i < lines . length ; i ++ ) { var numStart = lines [ i ] . indexOf ( ':' ) ; var numEnd = lines [ i ] . indexOf ( ':' , numStart + 1 ) ; // remove leading \ var fileName = lines [ i ] . substring ( 1 , numStart ) ; // ignore assets files if ( / ^_assets / . test ( fileName ) ) { continue } if ( ! ( fileName in grouped ) ) { grouped [ fileName ] = [ ] ; } grouped [ fileName ] . push ( { hit : lines [ i ] . substring ( numEnd + 1 ) . replace ( new RegExp ( searched , 'gi' ) , '<b>$&</b>' ) } ) ; } // sort by relevance var files = [ ] ; for ( var key in grouped ) { files . push ( { path : key , hits : grouped [ key ] } ) ; } callback ( null , files . sort ( function ( a , b ) { return b . hits . length - a . hits . length ; } ) ) ; } ) ; }
Performs a local-drive search by executing an os-specific command. Uses grep on linux, and findstr on windaube.  @param callback [Function] A callback function that will received following arguments: @option callback err [String] an error if somthing goes wrong, null otherwise @option callback results [Array] an array (that may be empty) containing object with the following properties - path [String] file path, relative to root folder. - hits [Array] array of search occurence (strings).
Performs a local - drive search by executing an os - specific command . Uses grep on linux and findstr on windaube .