Solved

internal database search engine

Posted on 2001-06-15
7
211 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Classic ASP migration directions 7 67
pass url parameter as session 9 48
An ASP query I cannot work out... 2 46
Live mode in DW, need to creae Session 4 79
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…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

863 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

22 Experts available now in Live!

Get 1:1 Help Now