【问题标题】:Faster way to search pdf text string in a folder在文件夹中搜索 pdf 文本字符串的更快方法
【发布时间】:2015-10-29 16:30:35
【问题描述】:

我急需帮助,我正在尝试在包含超过 5000 个 pdf 的文件夹目录中搜索文本字符串,该代码经过测试并且可以使用少于 100 个 pdf 并且它可以工作,但是一旦它到达限制它需要超过 5-10 分钟才能得出结果。非常感谢任何帮助:

'<%
'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
%>

【问题讨论】:

  • PDF 文件是二进制文件,您在这里将它们视为常规文本,这是不正确的。无论如何,您当前的结果很可能是不正确的,即使对于 100 个文件也是如此。
  • 疯狂的部分不是,它通过链接和适量的文件给我结果。

标签: pdf vbscript fso


【解决方案1】:

每次都进行完整搜索将花费很长时间。你最好使用像 Solr 这样的索引器来保持它的索引,就像搜索引擎一样,并快速返回结果。

这是一个很好的起点。 http://wiki.apache.org/solr/

【讨论】:

  • 有什么方法可以给我看一个例子吗?我看到了他们的解释,但我不熟悉那种语言,也没有给出任何可行的例子。
  • 仅供参考。我在我的服务器中使用 IIS 和 asp。
  • 网上有很多教程。只需浏览一个,如果您有具体问题,您可以随时发布一个包含详细信息的新问题。这不是放置另一个 solr 教程的合适位置。
  • 如果我没看错,它不适用于 IIS 7。有什么建议吗?
  • 我相信有一种方法可以使用 sharepoint 来做到这一点。这有点超出我个人的驾驶室,但值得研究。 en.wikipedia.org/wiki/Microsoft_Search_Server
猜你喜欢
  • 2013-01-27
  • 2016-10-25
  • 1970-01-01
  • 2011-06-26
  • 2017-04-03
  • 1970-01-01
  • 1970-01-01
  • 2020-06-11
  • 1970-01-01
相关资源
最近更新 更多