Я столкнулся с проблемой, что я хочу сделать текстовый поиск из 180 + PDF-файлов.Мой скрипт сначала извлекает данные из файлов pdf (pdf.js) один за другим, затем ищет текст из этих извлеченных данных и дает результаты.Каким-то образом это показывает правильный результат, но это очень медленно, и иногда мой компьютер зависает.
$('#submit').click(function(){
var searchString = $('#search').val().toLowerCase();
$('.result-container').html('');
permittedValues = pages.map(function(value) {//it iterates the array stroing pages i.e paths and other attributes
if(value.type=='pdf')
{
var PDF_URL = value.path;
var name = value.name;
PDFJS.getDocument(PDF_URL).then(function (PDFDocumentInstance) {
var found = 0;
var totalPages = PDFDocumentInstance.pdfInfo.numPages;
var pages = PDFDocumentInstance.numPages;
// Extract the text from each page
for (i = 1; i <= pages; i++) {
var pageText = '';
var string = "";
getPageText(i , PDFDocumentInstance).then(function(textPage){
if(searchString!='' && searchString!=' ' && searchString.length>3)
{
if(textPage.toLowerCase().includes(searchString))//searching text here
{
$('.names').each(function(){
if($(this).text()==name)
{
found = 1;
}
});
if(found!=1)
{
$('.result-container').append('<div class="result-row"><p class="names"><b><a href="http://localhost/search/design/Nxtenergy/'+value.path+'">'+ name +'</a></b></p>' +
'<cite>http://localhost/search/design/Nxtenergy/'+ value.path +'</cite>' +
'<p>'+ textPage.substring(0,500) +'...</p></div>');
}
return false;
}
}
});
}
}, function (reason) {
// PDF loading error
console.error(reason);
});
}
});
});
});
Можете ли вы дать мне какое-нибудь лучшее решение для этого.Спасибо