CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
山寨机中的战斗机! 程序优化工程师到底对IT界有没有贡献
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  Web 开发 >  ASP

怎么实现搜索引擎精确查询?

楼主kaidu(Roger)2002-03-23 08:59:38 在 Web 开发 / ASP 提问

我在Windows2000Server下编写了一个利用Index   Server进行站内查找的搜索引擎,但查出的结果中却有许多是不精确的,比如输入“杜凯”,查出的结果除了包含“杜凯”的文件外,就连含有“凯”的文件也搜索出来了,请教各位高手,正确的送100分,我的Email:kaiduv@263.net。我的程序的主要代码如下:  
   
  Sub   Initialize()  
      '指定搜寻范围  
      SearchScope   =   "/"  
      '设定LCID(Locale   Identifier)  
      LocaleID   =   "ZH-CN"  
      '指定每一页的资料笔数  
      PageSize   =   10  
   
      '设定其余变数  
      NewQuery   =   FALSE  
      UsedQuery   =   FALSE  
      QryStr   =   ""  
      '取得ASP文件的虚拟路径,包括文件名  
      ASPFile   =   Request.ServerVariables("PATH_INFO")  
  End   Sub  
   
  Sub   Judge_Method()  
      if   Request.ServerVariables("REQUEST_METHOD")   =   "POST"   then  
            QryStr   =   Request.Form("QryStr")  
            action=Request.Form("Action")            
  if   Request.Form("Action")   =   "执行"   then  
                  NewQuery   =   TRUE     '为一新查询  
            end   if  
      end   if  
   
      if   Request.ServerVariables("REQUEST_METHOD")   =   "GET"   then  
            QryStr   =   Request.QueryString("qu")  
            SearchScope   =   Request.QueryString("sc")  
            if   Request.QueryString("pg")   <>   ""   then  
                  NextPgNo   =   Request.QueryString("pg")  
                  NewQuery   =   FALSE  
                  UsedQuery   =   TRUE  
            else  
                  NewQuery   =   QryStr   <>   ""  
            end   if  
      end   if  
  End   Sub  
   
  Sub   Show_Mainform()          
      Response.Write   "<INPUT   TYPE='TEXT'   NAME='QryStr'   SIZE=46   "  
      Response.Write   "MAXLENGTH=100   VALUE='"   &   QryStr   &   "'>   "  
      Response.Write   "<INPUT   TYPE='SUBMIT'   NAME='Action'"  
      Response.Write   "   VALUE='执行'>   "  
      Response.Write   "<INPUT   TYPE='RESET'   NAME='Clear'"  
      Response.Write   "   VALUE='清除'>"      
      Response.Write   "</div>"  
      Response.Write   "</td>"  
      Response.Write   "</tr>"  
      Response.Write   "</table>"  
      Response.Write   "<hr></FORM>"  
  End   Sub  
   
  Sub   Init_ixsso()  
      Dim   StrLen  
   
      if   NewQuery   then     '若为新查询  
          Set   Session("Query")   =   Nothing  
          Set   Session("Recordset")   =   Nothing  
          NextRecNo   =   1  
          '去除查询字符串中的左、右双引号(如果有的话)  
          StrLen   =   len(QryStr)  
          if   left(QryStr,   1)   =   chr(34)   then  
                StrLen   =   StrLen   -   1  
                QryStr   =   right(QryStr,   StrLen)  
          end   if  
          if   right(QryStr,   1)   =   chr(34)   then  
                StrLen   =   StrLen   -   1  
                QryStr   =   left(QryStr,   StrLen)  
          end   if  
     
          Set   Q   =   Server.CreateObject("ixsso.Query")  
          Set   util   =   Server.CreateObject("ixsso.Util")          
          Q.Query   =   QryStr  
          Q.SortBy   =   "rank[d]"  
          Q.Columns   =   "DocTitle,   vpath,   filename,   size,   write,   characterization,   rank"  
         
          Q.MaxRecords   =   200  
   
          if   SearchScope   <>   "/"   then  
                util.AddScopeToQuery   Q,   SearchScope,   "deep"  
          end   if  
   
          if   LocaleID   <>""   then  
                Q.LocaleID   =   util.ISOToLocaleID(LocaleID)  
          end   if  
   
          set   RS   =   Q.CreateRecordSet("nonsequential")  
          RS.PageSize   =   PageSize  
          ActiveQuery   =   TRUE  
      ElseIf   UsedQuery   then  
          if   IsObject(   Session("Query")   )   And   _  
                IsObject(   Session("RecordSet")   )   then  
              set   Q   =   Session("Query")  
              set   RS   =   Session("RecordSet")  
   
              if   RS.RecordCount   <>   -1   and   NextPgNo   <>   -1   then  
                    RS.AbsolutePage   =   NextPgNo  
                    NextRecNo   =   RS.AbsolutePosition  
              end   if  
              ActiveQuery   =   TRUE  
          else  
              Response.Write   "错误   -   尚无任何查询条件!"  
          end   if  
      End   If     'NewQuery  
  End   Sub  
   
  Sub   Show_Query()  
      Dim   LastRecordOnPage  
      '若为现有查询  
      if   ActiveQuery   then  
          '如果Record   set有值,就一一取出,然后显示于前端浏览器  
          if   not   RS.EOF   then  
                LastRecordOnPage   =   NextRecNo   +   RS.PageSize   -   1  
                CurrentPage   =   RS.AbsolutePage  
                if   RS.RecordCount   <>   -1   AND   _  
                      RS.RecordCount   <   LastRecordOnPage   then  
                      LastRecordOnPage   =   RS.RecordCount  
                end   if  
                '显示视窗目前的资料编号  
                Response.Write   "文件"   &   NextRecNo   &   "   至   "  
                Response.Write   LastRecordOnPage   &   ",   "  
                '取出总笔数  
                if   RS.RecordCount   <>   -1   then  
                      Response.Write   "总共有<font   color='red'><b>"  
                      Response.Write   RS.RecordCount   &   "</b></font>"  
                end   if  
                Response.Write   "笔纪录符合查询条件:"   &   chr(34)   &   "<b>"  
                Response.Write   QryStr   &   "</b>"   &   chr(34)   &   "。<P>"  
   
                if   Not   RS.EOF   and   NextRecNo   <=   LastRecordOnPage   then  
                      Response.Write   "<table   border=0>"  
                      Response.Write   "<colgroup   width=105>"  
                end   if  
   
                Do   While   Not   RS.EOF   and   NextRecNo   <=   LastRecordOnPage  
                      '一一显示文件的标题、摘要、URL、文件大小及  
                      '最后修改日期。  
                      Response.Write   "<center>"  
                      Response.Write   "<p>"  
   
                      Response.Write   "<tr   class='RecordTitle'>"  
                      Response.Write   "<td   align=center   valign=top   "  
                      Response.Write   "BGCOLOR='#EEEEEE'   class='RecordTitle'>"  
                      '显示编号  
                      Response.Write   NextRecNo   &   "."  
                      Response.Write   "</td>"  
                      Response.Write   "<td   BGCOLOR='#EEEEEE'>"  
                      Response.Write   "<b   class='RecordTitle'>"  
                      '如果标题属性(Title)存在的话就显示Title,  
                      '否则显示出文件名  
                      if   VarType(RS("DocTitle"))   =   1   or   RS("DocTitle")   =   ""   then  
                            Response.Write   "<a   href='"   &   RS("vpath")   &   "'   "  
                            Response.Write   "class='RecordTitle'>"  
                            Response.Write   Server.HTMLEncode(RS("filename"))   &   "</a>"  
                      else  
                            Response.Write   "<a   href='"   &   RS("vpath")   &   "'   "  
                            Response.Write   "class='RecordTitle'>"  
                            Response.Write   Server.HTMLEncode(RS("DocTitle"))   &   "</a>"  
                      end   if  
                      Response.Write   "</b>"  
                      Response.Write   "</td></tr>"  
   
                      Response.Write   "<tr>"  
                      Response.Write   "<td>"  
   
                      Response.Write   "</td>"  
                      Response.Write   "<td   valign=top>"  
                      '显示摘要  
                      if   VarType(RS("characterization"))   =   8   and   _  
                            RS("characterization")   <>   ""   then  
                            Response.Write   "<b>摘要:</b>"  
                            Response.Write   Server.HTMLEncode(RS("characterization"))  
                      end   if  
                      Response.Write   "<p>"  
                      Response.Write   "<a   href='"  
                      Response.Write   RS("vpath")   &   "'   class='RecordStats'   "  
                      Response.Write   "style='color:blue;'>http://"  
                      Response.Write   Request("server_name")   &   RS("vpath")  
                      Response.Write   "</a><br>"  
                      if   RS("size")   =   ""   then  
                            Response.Write   "(大小和时间不详)"  
                      else  
                            Response.Write   "大小   "   &   RS("size")   &   "   个字节   -   "  
                            Response.Write   RS("write")   &   "   GMT"  
                      end   if  
                       
                      Response.Write   "</td></tr>"  
                      Response.Write   "<tr></tr>"  
   
                      RS.MoveNext  
                      NextRecNo   =   NextRecNo   +   1  
                Loop  
   
                Response.Write   "</table>"  
                Response.Write   "<P><BR>"  
          else       '   RS.EOF  
                if   NextRecNo   =   1   then  
                      Response.Write   "没有任何文件符合查询条件!<P>"  
                else  
                      Response.Write   "符合查询条件的文件均已显示!<P>"  
                end   if  
          end   if   '   NOT   RS.EOF  
   
          if   Q.OutOfDate   then  
                Response.Write   "<P><B>检索即将过期"  
                Response.Write   "(out   of   date)。</B><BR>"  
          end   if  
   
          if   Q.QueryIncomplete   then  
                Response.Write   "<P><B>查询无法完整完成"  
                Response.Write   "(Query   Incomplete)。</B><BR>"  
          end   if  
   
          if   Q.QueryTimedOut   then  
                Response.Write   "<P><B>查询时间太长"  
                Response.Write   "(Time   out)。</B><BR>"  
          end   if  
          '  
          Call   Show_Button()  
      end   if     'ActiveQuery  
  End   Sub  
   
  </script>  
   
  <HTML>  
  <HEAD>  
  <META   NAME="MS.LOCALE"   CONTENT="ZH-CN">  
  <META   HTTP-EQUIV="Content-Type"   CONTENT="text/html">  
  <TITLE>站内全文检索引擎</TITLE>  
  <LINK   REL=Stylesheet   TYPE="text/css"   HREF="ews.css">  
  <%  
  '搜寻范围  
      Call   Initialize()  
  '判断Request_Method      
      Call   Judge_Method()  
  %>  
   
  </HEAD>  
  <BODY   background="/images/marble2c.GIF"   >  
  <right>  
  <%response.write   ""&action&""%>  
  <%  
      Call   Show_Mainform()  
      Call   Init_ixsso()  
      Call   Show_Query()  
  %>  
  </right>  
  </BODY></HTML>  
  问题点数:100、回复次数:4Top

1 楼kaidu(Roger)回复于 2002-03-23 09:16:26 得分 0

怎么没人回答啊?小弟很着急呢!Top

2 楼karma(无为MS MVP)回复于 2002-03-23 09:36:51 得分 100

can   you   add   double   quotes   around   your   word?Top

3 楼tripofdream(梦之旅)回复于 2002-03-23 09:41:41 得分 0

index   server的查询是基于"词"(word)的,对于中文是把每个字视为一个词的;要想精确查询,可以在查询出来的结果中再用instr()做判断.Top

4 楼kaidu(Roger)回复于 2002-03-23 09:48:16 得分 0

是在“关键字”上加双引号吗?怎么在结果中使用instr()进行过滤呢?Top

相关问题

  • 怎么实现搜索引擎精确查询?
  • 如果实现搜索引擎
  • 高分求解,用JAVASCRIPT能实现搜索引擎功能吗?
  • 重分悬赏---搜索引擎的实现原理
  • 现在的搜索引擎都支持二次搜索(就是第一次查询后,第二次可以在“查询结果”中再查。如http://e.pku.edu.cn),不知是如何实现的?
  • 搜索引擎!
  • 搜索引擎
  • -->关于搜索引擎:请问在结果中查找是怎么实现的???
  • 有谁知道GOOGLE搜索引擎是怎么来存放每一个查询的临时结果的
  • 在数据库中怎么用关键字查询?就象搜索引擎那样??

关键词

得分解答快速导航

  • 帖主:kaidu
  • karma

相关链接

  • Web开发类图书

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
北京创新乐知广告有限公司 版权所有, 京 ICP 证 070598 号
世纪乐知(北京)网络技术有限公司 提供技术支持
Copyright © 2000-2008, CSDN.NET, All Rights Reserved
GongshangLogo