Solved

internal database search engine

Posted on 2001-06-15
7
214 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
ID: 6195093
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
ID: 6195393
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
ID: 6195484
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
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 2

Accepted Solution

by:
dwalsarie earned 100 total points
ID: 6195618
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
ID: 6195621
</form>
</table>
</table>
</center>

must be

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

ofcourse :)
0
 
LVL 4

Expert Comment

by:epeele
ID: 6195704
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
ID: 6199458
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:  The Exchange of information …
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

856 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