欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

如何实现全文检索?

程序员文章站 2022-03-25 23:40:56
<%@ language="vbscript" %>    

<%@ 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>

[1]