2015-10-29 44 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教程的地方。 –