0

I'm in desperate need of help, I'm trying to search a text string in a folder directory containing over 5000 pdf's, the code was tested and working with less than 100 pdfs and it works, but once it reaches the limit it takes over 5-10 minutes to come up with a result. ANY help is greatly appreciated:

'<%
'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
%>
rhens
  • 4,791
  • 3
  • 22
  • 38
  • 2
    PDF files are binary files, you are treating them here as regular text, this is not correct. It's very likely that your current results are incorrect anyway, even for 100 files. – yms Oct 29 '15 at 17:01
  • Crazy part is that is not, it is giving me the results with the link and the right amount of files. – Learning rookie Oct 29 '15 at 17:58

1 Answers1

1

Doing a full search every time is going to take forever. You would be better off using an indexer like Solr to keep an index of it the way a search engine would and return results quickly.

This is a good place to start. http://wiki.apache.org/solr/

Anonymous Man
  • 2,776
  • 5
  • 19
  • 38
  • Any way you can show me an example? I see their explanation but I'm not familiar with that language and is not giving any working examples. – Learning rookie Oct 29 '15 at 16:45
  • FYI. I'm using IIS in my server with asp. – Learning rookie Oct 29 '15 at 17:10
  • There are many tutorials online. Just go through one and if you have specific issues you can always post a new question with details. This would not be an apporpriate place to put yet another solr tutorial. – Anonymous Man Oct 29 '15 at 18:25
  • If I'm reading this correctly it doesn't work with IIS 7. Any suggestions? – Learning rookie Oct 29 '15 at 21:19
  • There is, I believe, a way to do this using sharepoint. That's a little outside my wheelhouse personally but it's worth looking into. https://en.wikipedia.org/wiki/Microsoft_Search_Server – Anonymous Man Oct 29 '15 at 21:32