2015-10-29 46 views
0

我急需幫助,我試圖搜索包含超過5000個pdf的文件夾目錄中的文本字符串,代碼已經過測試並且使用少於100個PDF和它的工作原理,但一旦達到極限,需要花費5-10分鐘才能得出結果。任何幫助非常感謝:在文件夾中搜索pdf文本字符串的更快方法

'<% 
'Search Text 
Dim strtextToSearch 
strtextToSearch = Request("TextToSearch") 

'Now, we want to search all of the files 
Dim fso 

'Constant to read 
Const ForReading = 1 
Set fso = Server.CreateObject("Scripting.FileSystemObject") 

'Specify the folder path to search. 
Dim FolderToSearch 
FolderToSearch = "C:\inetpub\site\Files\allpdfs\" 

'Proceed if folder exists 
if fso.FolderExists(FolderToSearch) then 

    Dim objFolder 
    Set objFolder = fso.GetFolder(FolderToSearch) 

    Dim objFile, objTextStream, strFileContents, bolFileFound 
    bolFileFound = False 

    Dim FilesCounter 
    FilesCounter = 0 'Total files found 

    For Each objFile in objFolder.Files 
     Set objTextStream = fso.OpenTextFile(objFile.Path,ForReading) 
     'Read the content 
     strFileContents = objTextStream.ReadAll 
     If InStr(1,strFileContents,strtextToSearch,1) then 
     '%> 
      <a href="http://go.to.mysite.com/files/allpdfs/<%Response.Write objFile.Name%>" target="_blank"> 
     '<% 
      Response.Write objFile.Name & "</a><br>" 
      FilesCounter = FilesCounter + 1 
     End If 
     objTextStream.Close 
    Next 

    if FilesCounter = 0 then 
     Response.Write "Sorry, No matches found." 
    else 
     Response.Write "Total files found : " & FilesCounter 
    end if 

    'Destroy the objects 
    Set objTextStream = Nothing 
    Set objFolder = Nothing 
else 
    Response.Write "Sorry, invalid folder name" 
end if 
Set fso = Nothing 
%> 
+2

PDF文件是二進制文件,您在這裏將它們視爲常規文本,這是不正確的。無論如何,您的當前結果很可能不正確,即使是100個文件也是如此。 – yms

+0

瘋狂的部分是不是,它給我的結果與鏈接和適量的文件。 –

回答

1

每次做一個完整的搜索將永遠持續下去。使用Solr等索引器可以更好地保持搜索引擎的索引並快速返回結果。

這是一個很好的開始。 http://wiki.apache.org/solr/

+0

任何方式,你可以告訴我一個例子?我看到他們的解釋,但我不熟悉那種語言,並沒有給出任何工作示例。 –

+0

供參考。我在asp服務器中使用IIS。 –

+0

網上有很多教程。只要通過一個,如果你有特定的問題,你可以隨時發佈一個新的問題與細節。這將不是一個適合放置另一個solr教程的地方。 –