ASP intra-Site Search

Source: Internet
Author: User
Below Code You can copy and paste all the files to a search. asp file to achieve full-text retrieval of static pages. Suitable for websites with few pages, it is estimated that the performance of over 100 pages is poor.

< %
Head =   " Intra-Site Search "
Searchstring = Request ( " Searchstring " )
Count = 0

' Convert the actual path of the current directory to a virtual path
Function Unmappath (PATH)
Unmappath =   Replace ( Mid (Path, Len (Server. mappath ( " / " )) +   1 ), "" , " / " )
End Function


Function Searchfile (F, S, title)
Set Fo = FS. opentextfile (f)
Content = Fo. readall
Fo. Close
Searchfile =   Instr ( 1 , Content, S, vbtextcompare) >   0  
If Searchfile Then
Pos1 =   Instr ( 1 , Content, " <Title> " , Vbtextcompare)
Pos2 =   Instr ( 1 , Content, " </Title> " , Vbtextcompare)
Title =   ""
If Pos1 >   0   And Pos2 >   0   Then
Title =   Mid (Content, pos1 +   7 , Pos2 - Pos1 -   7 )
End   If
End   If
End Function

Function Filelink (F, title)
Vpath = Unmappath (F. Path)
If Title =   ""   Then Title = F. Name
Filelink =   " <A href = "" "   & Vpath &   " ""> "   & Title &   " </A> "
Filelink =   " <Ul> · "   & Filelink &   " </Ul> "
End Function

Sub Searchfolder (FD, S)
Found =   False
For   Each F In FD. Files
Pos =   Rev (F. path, " . " )
If Pos >   0   Then
EXT =   Mid (F. Path, POS +   1 )
Else
EXT =   ""
End   If
If   Lcase (EXT) =   " Htm "   Then
If Searchfile (F, S, title) Then
Response. Write filelink (F, title)
Count = Count + 1
' Response. Write CSTR (count)
End   If
End   If
Next

For   Each SFD in FD. subfolders
Searchfolder SFD, S
Next
End sub
% >
< Html >

< Head >
< Meta HTTP - Equiv = " Content-Type " Content = " Text/html; charsets = gb_2312-80 " >
< Title > < % = Head % > </ Title >
</ Head >

< Body bgcolor = " # Ffffff " >

< H1 > < % = Head % > </ H1 >

< HR >

< ! -- Note that search. asp is the file and can be modified as needed! -->

< Form Action = " Search. asp " Method = " Get " >  
< P > Enter the content to search: < Input type = " Text "
Size = " 20 " Name = " Searchstring " Value = " <% = Searchstring %> " >   < Input
Type = " Submit " Value = " Search " >   </ P >
</ Form >
< %
Set FS = Server. Createobject ( " Scripting. FileSystemObject " )
Set FD = FS. getfolder (server. mappath ( " ./ " )) ' Set the start search path (all its subdirectories will be traversed and the current directory is search. asp )!

If Searchstring <>   ""   Then
Response. Write " <H2> Search <font color = Red> "   & Searchstring &   " </Font> result: </H2> <p> "
Searchfolder FD, searchstring
End   If
% >
< HR >
</ Body >
</ Html >


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.