Using ASP to do Full-text search

Source: Internet
Author: User
Tags dsn file system
Absrtact: Through the word search related to the full text is the browser-side commonly used methods, ASP, similar to CGI, can also be a simple text format Full-text search
Keyword: ASP search intranet Web page ADO data source
In the internet/intranet of a certain kind of information to do detailed browsing and Full-text search is often encountered. ASP is a Microsoft developed for the production of Dynamic Web pages of a server-side
Script style (or authoring environment). It uses simple scripting languages like VBScript or JavaScript, integrates in HTML code, and performs data interviews on the server side in response to browser-side requests
Ask and process (or object) calls and produce scripting languages that are executed by the browser side. This paper introduces the method of writing Full-text retrieval code with ASP.
Method Introduction:
Determines which files are retrieved. Save them in the same folder. The type of file can be any text type (including. htm Web page file type)
Establish a database of retrieved documents. The main include file name, file title and so on.
Access the database in ADO mode. Sets the Recordset object.
Open the file that is pointed to by the current record in the recordset, individually. Compares the full-text text of a file with a lookup string.
Prints the eligible file headers to the client Web page and adds a hyperlink to the file that the user chooses to browse.
Technical points:
The data source. Before creating the script, use ODBC in the WINDOWS95 Control Panel to specify the database and its drivers to be accessed, identified by the data source name (DSN).
Matches the length of a string. Because the data of the browser-side is encoded to the server, the data obtained by the ASP through the object request is not the useful information entered by the user.
, so it has to be dealt with. You can attach a flag character (such as # or CHR (7)) after the input string. This article takes another approach, that is, to calculate the length of valid information. To intercept the required
String.
Creates a script file system object Scripting.FileSystemObject, which opens the text stream for reading.
Characteristics:
directly to the. htm file for Full-text search, save a lot of conversion process. The. htm file is also used for Web page display.
Application of ASP, simple and clear, easy to implement.
This example ASP code:
〈% @LANGUAGE = "VBSCRIPT"%〉
〈html〉
〈head〉
〈metaname= "generator" content= "MicrosoftFrontPage3.0"
〈metahttp-equiv= "Content-type" content= "text/html;charset=gb_2312-80"
〈title〉documenttitle〈/title〉
〈metaname= "Microsoftborder" content= "Tl,default" 〉〈/head〉
〈bodybackground= "/ie/images/watermrk.gif" bgproperties= "FIXED" bgcolor= "#00FFFF"
〈%
Mousepointer=13
Setconn1=server.createobject ("ADODB.") Connection ")
Conn1.open "Dsn=cznj"
Setrcst1=conn1.execute ("Select*frompages_catalogue")
Sch_str=request.form ("Text1")
Doubbytes=len (SCH_STR) \2
Sch_str=left (Sch_str,doubbytes)
Response.Write "〈strong〉〈center〉〈h2〉 Find results 〈/h2〉〈hr〉〈br〉〈/strong〉"
Dimresult
Result=false
Response.Write "〈ul〉"
Dowhilenotrcst1.eof
Tit=rcst1.fields ("File_title")
Fn=rcst1.fields ("file_name")
File_name=server.mappath ("/") & "\njweb\private\" &fn
To_find=text_match (FILE_NAME,SCH_STR)
Ifto_findthen
Url= "private/" &fn
Response.Write "〈left〉〈li〉〈h4〉〈ahref=" &url& "" &tit
endif
Rcst1.movenext
Result=resultorto_find
Loop
Response.Write "〈/ul〉"
Ifnotresultthen
Response.Write "〈h3〉〈i〉 not Found!" 〈/i〉〈/h3〉 "
endif
Mousepointer=0
%〉
〈scriptrunat= "Server" language= "VBScript"
Functiontext_match (filename,search_string)
Dimretstring
Dimfind_pos
Dimfso,a
Dimdone
Text_match=false
Setfso=server.createobject ("Scripting.FileSystemObject")
Seta=fso. OpenTextFile (filename,1,false) "forreading--〉1
Done=a.atendofstreamortext_match
Dowhilenotdone
Retstring=a.readline
Find_pos=instr (retstring,search_string)
Iffind_pos〉0thentext_match=true
Done=a.atendofstreamortext_match Loop
A.close
Endfunction
〈/script〉
〈/body〉
〈/html〉


Related Article

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.