Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

internal database search engine

Posted on 2001-06-15
7
Medium Priority
?
220 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:Michel Sakr
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 2

Accepted Solution

by:
dwalsarie earned 300 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
Integration Management Part 2
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Suggested Courses

824 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