Solved

internal database search engine

Posted on 2001-06-15
7
210 Views
Last Modified: 2012-06-21
I want to develop a system where has an internal search engine.
This search engine will search through a description of files.
The files will be stored into directory.
SQL server 7.0 will be used to create a table that has fields like filename, filesize, filedates, filedesc, and etc.
When SQL command search through the filedesc fields, a links that related to the keywords will be shown.
Once the links is clicked, it will either open the files (if the user have the application) or it will be downloaded by the user.

My question is:
How to link between the file and the filedesc field (I mean the logic and the syntax)??
Or
Do you have other solutions for the system.

Thank you..
0
Comment
Question by:anwar13
7 Comments
 
LVL 20

Expert Comment

by:Silvers5
Comment Utility
in the table you add also file path.. and you display the filnames of matched to search records with an href of each where you include the path.. your solution is optimal..
0
 
LVL 5

Expert Comment

by:gbaren
Comment Utility
It's pretty simple. Let's say your table is:

FilesTable
----------
file_id
FilePath
FileDescr
FileSize
FileDate


Your ASP code would be:

<%
dim conn, rs
set conn = Server.CreateObject("ADODB.Connection")
conn.open "MyDSN"
set rs = conn.execute("select * from FilesTable where file_id in (" & GetIDListFromSearch() & ")"
while not rs.EOF
   Response.Write "<a href='" & rs("FilePath") & "'>"
   Response.Write rs("FileDescr")
   Response.Write "</a"
   rs.MoveNext
wend
set rs = nothing
conn.close
%>
0
 
LVL 4

Expert Comment

by:epeele
Comment Utility
Silvers5 answer is the most straightforward.  The path would be written to the hyperlink, which when clicked, would download/open the file.

However, if these files are to be "secure" meaning that you don't want someone to be able to just type in a URL to the file when you expose the path to the file, then you store the files in a directory outside of the webroot and use the StreamObject to write the file the clients browser.
For example:

<!--METADATA TYPE="typelib"
      UUID="00000205-0000-0010-8000-00AA006D2EA4"
     NAME="ADODB Type Library"
-->
<%

  'Fetch the name of your file
  'with your database code here  
  strFileName = objRS("FileName")
  strContentType = objRS("ContentType")

  'Create a stream object
  Dim objStream
  Set objStream = Server.CreateObject("ADODB.Stream")
 
  'Set your default path  
  strPath = "D:\SomeFolder\"

  'Open the file
  objStream.Type = adTypeBinary
  objStream.Open
  objStream.LoadFromFile strPath & strFileName
 
  'Output the contents of the stream object
  Response.ContentType = strContentType 'such as "image/gif"
  Response.BinaryWrite objStream.Read
 
  'Clean up....
  objStream.Close
  Set objStream = Nothing
%>

0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 2

Accepted Solution

by:
dwalsarie earned 100 total points
Comment Utility
Files
----------
fileID
FilePath
FileDescr
FileSize
FileDate

<%

 SearchQuery = Request("q")

 If SearchQuery <> "" Then

    SearchQuery = Replace(SearchQuery, "'", "''")

    Dim cn
    Dim rs

    Set cn = Server.CreateObject("ADODB.Connection")
    cn.Open "DSN=YOURDSNHERE", "username", "password"
   
    Set rs = cn.Execute("SELECT * FROM Files WHERE FileDescr LIKE '% " & SearchQuery & " %';")

    If Not rs.EOF Then

      %><font face="Arial"><ul><%    

      While Not rs.EOF %>
       
       <li>
       <a href="<%=rs("FilePath")%>"><%=rs("FilePath")%></a><br><%=rs("FileDescr")%><br><font color="#CCCCCC">Size: <%=rs("FileSize")%> - Date: <%=rs("FileDate")%></font>
       </li>    
<%
      rs.MoveNext
    Wend
    %></ul></font><%
  Else
%>No results were found<%
  End If
  rs.Close
  Set rs = Nothing
  cn.Close
  Set cn = Nothing

Else
%>
<center>
<table width=600 bgcolor="#EEEEEE">
<form method="POST" action="<%=Request.ServerVariables("URL")%>">
<tr><td>
<input type="text" size=40 name="q">&nbsp;
<input type="submit" value="Search">
</td></tr>
</form>
</table>
</table>
</center>
<%
End If
%>
0
 
LVL 2

Expert Comment

by:dwalsarie
Comment Utility
</form>
</table>
</table>
</center>

must be

</form>
</table>
</center>

ofcourse :)
0
 
LVL 4

Expert Comment

by:epeele
Comment Utility
woops... database stuff would be done on the Search Results page, not the page that downloads the file. Changes made below:

search_results.asp

<a href="showpage.asp?file=<%=strFileName%>&type=<%=strContentType%>">Keyword</a>

showpage.asp

<!--METADATA TYPE="typelib"
     UUID="00000205-0000-0010-8000-00AA006D2EA4"
    NAME="ADODB Type Library"
-->
<%

 strFileName = Request.QueryString("file")
 strContentType = Request.QueryString("type")

 'Create a stream object
 Dim objStream
 Set objStream = Server.CreateObject("ADODB.Stream")
 
 'Set your default path  
 strPath = "D:\SomeFolder\"

 'Open the file
 objStream.Type = adTypeBinary
 objStream.Open
 objStream.LoadFromFile strPath & strFileName
 
 'Output the contents of the stream object
 Response.ContentType = strContentType 'such as "image/gif"
 Response.BinaryWrite objStream.Read
 
 'Clean up....
 objStream.Close
 Set objStream = Nothing
%>
0
 

Author Comment

by:anwar13
Comment Utility
I am really sorry to make you guys waiting for me to try each code...
I never code in asp before that's why it takes quite long for me to learn :P

Seems the working comment that works when i try is only
by dwalsarie which is easier to understand.


The only problem is it can't list out the result, it always display:

No results were found

but when i delete this:

WHERE FileDescr LIKE '% " & SearchQuery & " %'

It can list all the files in the database and works well.

So the search engine can't work well...

Thank you for the rest of your comments, It's really helpful for me in future though it didn't work for this case especially for epeele.

Thank you...
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now