如何实现全文检索?

时间:2010-05-24 18:24:00 

 我们可以先建立一个包含文件名,文件标题的待检索文件的数据库,然后,用ADO方式来访问它,并建立记录集对象。

具体代码和说明见下:
  

<%@ LANGUAGE="VBSCRIPT" %>
  <html>
  <head>
  <meta NAME="GENERATOR" Content="Microsoft FrontPage 3.0">
  <meta HTTP-EQUIV="Content-Type" content="text/html; charset=gb_2312-80">
  <title>精彩春风之全文检索</title>
  <meta name="Microsoft Border" content="tl, default">
</head>
   <body BGPROPERTIES="FIXED" BGCOLOR="#00FFFF">
<%
  mousepointer=13
  Set Conn1 = Server.CreateObject("ADODB.Connection")
  conn1.open "DSN=intels"
  Set rcst1 = conn1.execute("SELECT * FROM pages_catalogue")
  sch_str=request.form("text1")
  doubbytes=len(sch_str)\2 
  sch_str=left(sch_str,doubbytes)
' 匹配字串的长度.预处理Request取得的数据(用户输入的有用信息), 通过计算有效信息长度来截取所需的字串.我们也可以在输入字串后附加一标志字符(如#或chr(7))来处理.
  Response.Write "<CENTER>检索结果<HR><Br>"
  Dim result
  result =false
  Response.Write "<UL>"
  do while not rcst1.eof
  tit=rcst1.fields("file_title")
  fn=rcst1.fields("file_name")
  file_name= Server.MapPath ("/") & "\song\chunfeng\" & fn
  to_find=text_match(file_name,sch_str)
' 逐个打开记录集中当前记录所指向的文件。用查找的字串对文件的全文本进行匹配比较
  if to_find then
  url="chunfeng/" & fn
  Response.Write "<A HREF=" & url & ">
" & tit
  end if
  rcst1.movenext
  result=result or to_find
  loop
  Response.Write "</UL>"
' 把符合条件的文件标题以超级链接形式输出到客户端
  if not result then
  Response.Write "对不起,没有找到!"
  end if
  mousepointer=0
  %>
  <script RUNAT="Server" LANGUAGE="VBScript">
  function text_match(filename,search_string)
  dim retstring
  dim find_pos
  Dim fso, a
  dim done
  text_match=false
  Set fso = Server .CreateObject("Scripting.FileSystemObject
")
' 创建脚本的文件系统,打开文本流以读入
  Set a = fso.OpenTextFile(filename, 1, FALSE) 
done=a.AtEndOfStream or text_match
  Do While not done
  retstring = a.ReadLine
  find_pos=instr(retstring,search_string)
  if find_pos>0 then text_match=true
  done=a.AtEndOfStream or text_match
  Loop
  a.Close
  end function
  </script>
  </body>
  </html>

标签:检索,全文,asp
0
投稿

猜你喜欢

  • 如何获取文件的名称和扩展名?

    2009-11-23 20:50:00
  • 使链接具有最大化、最小化的功能代码

    2008-02-24 16:43:00
  • 交互设计实用指南系列(12)—避免出错

    2010-04-12 13:02:00
  • 让JavaScript拯救HTML5的离线存储[译]

    2009-05-15 12:26:00
  • Oracle 函数大全

    2009-07-23 14:29:00
  • java.sql.SQLException: 内部错误: Unable to construct a Datum from the specified input

    2010-07-16 13:23:00
  • 简单form标准化实例——语义结构

    2007-06-20 16:32:00
  • W3C 接连推出 7 个 HTML 草案

    2010-03-10 10:37:00
  • MySQL表设计优化与索引 (五)

    2010-10-25 20:24:00
  • css+JavaScript实现PDF、ZIP、DOC链接的标注

    2007-05-11 17:03:00
  • Windows XP操作系统下的MYSQL安装过程

    2008-11-24 12:52:00
  • 新 API 寻求让 JavaScript 操作本地文件

    2009-11-27 18:28:00
  • MySQL聚焦Web 2.0可扩展性

    2012-01-05 19:02:19
  • IE7兼容模式与兼容视图

    2010-06-28 18:48:00
  • 用err.raise自定义错误信息

    2008-02-20 12:48:00
  • 模拟下拉菜单[兼容IE系列以及火狐]

    2009-12-13 10:23:00
  • Fibonacci数,Θ(log n)

    2010-03-28 13:28:00
  • 一个二级伸缩下拉菜单代码

    2008-06-24 18:12:00
  • FLASH 全屏播放

    2008-07-19 11:36:00
  • 重新编译PLSQL中的无效对象或者指定的对象 的方法

    2009-02-26 10:41:00
  • asp之家 网络编程 m.aspxhome.com