내 구현에서 사용자가 클라이언트에서 검색하는 경우 문자열이 파일의 일부인지 확인하고 싶습니다. 나는 그 라인 데이터를 응답으로 클라이언트에 다시 보내고있다.파일 시스템에서 데이터를 읽고 클라이언트에게 전체 메시지를 보내는 방법은 무엇입니까?
내 문제는 사용자가 testid012
을 검색하려고한다고 가정합니다. 따라서 현재 코드에서는 검색 문자열이 포함 된 단 한 줄만 찾습니다. 대신 검색 문자열 (여기서는 testid012
)을 포함하는 여러 줄의 응답을 보내려합니다. 이게 가능합니까?
searchService.js
fs.readFile('logs/dit/' + logfile.filename, 'utf8', function (err, data) {
if (err) {
return done(err);
}
var lines = data.split('\n'); // get the lines
lines.forEach(function(line) { // for each line in lines
if (line.indexOf(searchStr) != -1) { // if the line contain the searchSt
results.push({
filename:logfile.filename,
value:line
});
}
});
// when you are done reading the file
done();
});
DIT/
testid012 Lorem test Ipsum is simply dummy text text of the printing and typesetting industrytestid Lorem test Ipsum is simply dummy text text of the printing and typesetting industrytestid Lorem test Ipsum is simply dummy text text of the printing and typesetting industry
Lorem test Ipsum is simply dummy text text of the printing and typesetting industry,testid Lorem test Ipsum is simply dummy text text of the printing and typesetting industry
testid013 Lorem test Ipsum is simply dummy text text of the printing and typesetting industry,testid Lorem test Ipsum is simply dummy text text of the printing and typesetting industrytestid Lorem test Ipsum is simply dummy text text of the printing and typesetting industry
Lorem test Ipsum is simply dummy text text of the printing and typesetting industry
이 방법을 사용하지 않는 것이 좋습니다. Solr 내부에서 파일의 색인을 생성하고 Solr에 해당 검색어를 쿼리하거나 적어도 Solr이 없으면 사용하십시오. 그것은 당신이 가지고있는 어떤 데이터베이스에서도 권장하지는 않지만 적어도 파일 검색은 당신이하는 것처럼하는 것이 아닙니다. –
이 요구 사항에 대해 데이터베이스를 사용할 수 없으며 파일 검색을 수행해야합니다. 좋은 예제는 어떻게 FS를 사용하여 달성 할 수 있습니다. – hussain