Solved

internal database search engine

Posted on 2001-06-15
7
216 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

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 informatio…
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…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

734 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