ASP.NET网站全文检索(代码部分)

news/2024/5/8 21:11:16/文章来源:https://blog.csdn.net/senbar/article/details/637796

ASPX页面代码如下:

< tr >
    
< td  class ="record"  height ="20" > 关 键 词:
    
< asp:textbox  id ="txtQuery"  accessKey ="Q"  runat ="server"  Width ="250px"  MaxLength ="50" ></ asp:textbox > &nbsp;
    
< asp:button  id ="btnSearch"  runat ="server"  Text ="搜索"  EnableViewState ="False" ></ asp:button ></ td >
</ tr >
< tr >
    
< td  height ="10" > 查询方式:
    
< asp:dropdownlist  id ="cboQueryType"  accessKey ="T"  runat ="server"  Width ="250px"  EnableViewState ="False" >
    
< asp:ListItem  Value ="All"  Selected ="True" > 包含全部的字词 </ asp:ListItem >
    
< asp:ListItem  Value ="Any" > 包含任何一个字词 </ asp:ListItem >
    
< asp:ListItem  Value ="Boolean" > 布尔表达式查询 </ asp:ListItem >
    
< asp:ListItem  Value ="Exact" > 全字匹配 </ asp:ListItem >
    
< asp:ListItem  Value ="Natural" > 自然语言查询 </ asp:ListItem >
    
</ asp:dropdownlist >
    
</ td >
</ tr >
< tr >
    
< td  class ="record"  height ="20" > 查询范围:
    
< asp:dropdownlist  id ="cboDirectory"  accessKey ="D"  runat ="server"  Width ="250px"  EnableViewState ="False" >
    
< asp:ListItem  Value ="/"  Selected ="True" > 整个网站 </ asp:ListItem >
    
</ asp:dropdownlist >
    
</ td >
</ tr >
< tr >
    
< td  class ="record"  height ="20" >< asp:label  id ="lblResultCount"  runat ="server"  Font-Italic ="True"  visible ="False"  EnableViewState ="False" ></ asp:label ></ td >
</ tr >
< tr >
    
< td  vAlign ="top"  height ="210" >
    
< asp:datagrid  id ="dgResultsGrid"  runat ="server"  PageSize ="15"  AllowPaging ="True"  AutoGenerateColumns ="False"
        Visible
="False"  GridLines ="None"  EnableViewState ="False" >
        
< ItemStyle  HorizontalAlign ="Left"  VerticalAlign ="Top" ></ ItemStyle >
        
< HeaderStyle  Font-Bold ="True" ></ HeaderStyle >
        
< Columns >
            
< asp:TemplateColumn  HeaderText ="排名" >
                
< HeaderStyle  Width ="40px" ></ HeaderStyle >
                
< ItemTemplate >
                    
<% # (cint(DataBinder.Eval(Container, "DataSetIndex"))) + 1  %>
                    
</ ItemTemplate >
                    
</ asp:TemplateColumn >
                    
< asp:TemplateColumn  HeaderText ="文档信息" >
                    
< ItemStyle  HorizontalAlign ="Left"  VerticalAlign ="Top" ></ ItemStyle >
                    
< ItemTemplate >
                    
< p >
                    
< href ='<%#  DataBinder.Eval(Container.DataItem, "VPath")% > ' target="_blank">
                    
<% # GetTitle(Container.DataItem) %>
                    
</ a >
                    
< br >
                    
<% # GetCharacterization(Container.DataItem) %>
                    
< br >
                    
< i >< href ='<%#  DataBinder.Eval(Container.DataItem, "VPath")% > ' target="_blank">http:// <% # Request.ServerVariables("SERVER_NAME") %><% # DataBinder.Eval(Container.DataItem, "VPath") %> </ a >
                    -
                    
<% # GetFileSize(Container.DataItem) %>
                    k 
</ i >
                    
</ p >
                
</ ItemTemplate >
            
</ asp:TemplateColumn >
            
</ Columns >
        
< PagerStyle  Visible ="False" ></ PagerStyle >
    
</ asp:datagrid >
    
</ td >
</ tr >

后台代码,使用VB.NET书写:

 

  '  绑定查询结果
         Private   Sub BindSearch()

            
Dim dbAdapter As OleDbDataAdapter = New System.Data.OleDb.OleDbDataAdapter
            
Dim oleDbSelectCommand1 As OleDbCommand = New System.Data.OleDb.OleDbCommand
            
Dim dbConnection As OleDbConnection = New System.Data.OleDb.OleDbConnection
            
Dim ds As DataSet = New DataSet("Results")
            
Dim rows As Integer = 0

            dbAdapter.SelectCommand 
= oleDbSelectCommand1
            oleDbSelectCommand1.Connection 
= dbConnection
            dbConnection.ConnectionString 
= "Provider=MSIDXS.1;Integrated Security .='';Data Source=Web"

            Try
                dbAdapter.SelectCommand.CommandText 
= Command
                
If CStr(ViewState("KEY")) <> "" Then
                    dbAdapter.Fill(ds)
                    rows 
= ds.Tables(0).Rows.Count
                
Else
                    lblResultCount.Text 
= "请输入关键词进行查询!"
                End If

                
If Not ds Is Nothing AndAlso rows > 0 Then
                    
' 自定义分页,与查询逻辑无关
                    ViewState("TOTALROWS"= rows
                    CalculatePage()

                    dgResultsGrid.AllowPaging 
= True
                    dgResultsGrid.PageSize 
= CInt(ViewState("PAGESIZE"))
                    dgResultsGrid.CurrentPageIndex 
= CInt(ViewState("PAGEINDEX")) - 1

                    lblResultCount.ForeColor 
= Color.Black
                    lblResultCount.Text 
= String.Format("找到 {0} 个相关网页", rows)

                    dgResultsGrid.DataSource 
= ds
                    dgResultsGrid.DataBind()
                    dgResultsGrid.Visible 
= (rows > 0)
                
Else
                    ViewState(
"TOTALROWS"= 0
                    CalculatePage()
                
End If

            
Catch ex As Exception
                lblResultCount.ForeColor 
= Color.Red
                lblResultCount.Text 
= String.Format("无法执行特定的查询: {0}", ex.Message)
                dgResultsGrid.Visible 
= False
            
Finally
                lblResultCount.Visible 
= True
            
End Try
            ' 自定义分页
            BindNavigate()

        
End Sub


 

Private   ReadOnly   Property Command() As String
            
Get
                
Dim query As String
                query 
= String.Format("SELECT Rank, VPath, DocTitle, Filename, Size, Characterization, Write FROM SCOPE('DEEP TRAVERSAL OF ""{0}""') WHERE  Not CONTAINS(FileName,'""*.txt"" OR ""*.js"" OR ""*.css"" OR ""*.config"" OR ""*.xml""')"CStr(ViewState("DIR")))

                
Dim type As String = CStr(ViewState("TYPE")).ToLower()
                
Dim fmt As String = " AND (CONTAINS('{0}') OR CONTAINS(DocTitle, '{0}'))"
                Dim text As String = CStr(ViewState("KEY")).Replace(";""").Trim

                
If type = "all" Or type = "any" Or type = "boolean" Then
                    
Dim words() As String = Split(text, " ")
                    
Dim len As Integer = words.Length
                    
Dim i As Integer

                    
For i = 0 To len - 1 Step i + 1
                        
Dim word As String = words(i)
                        
If type = "boolean" AndAlso (String.Compare(word, "and"True= 0 OrElse String.Compare(word, "or"True= 0 OrElse String.Compare(word, "not"True= 0 OrElse String.Compare(word, "near"True= 0Then
                        
ElseIf word <> "" Then
                            words(i) 
= String.Format("""{0}""", word)

                            
If i < len - 1 Then
                                
If type = "all" Then
                                    words(i) 
+= " AND"
                                ElseIf type = "any" Then
                                    words(i) 
+= " OR"
                                End If
                            
End If
                        
End If
                    
Next

                    query 
+= String.Format(fmt, String.Join(" ", words))

                
ElseIf type = "exact" Then
                    query 
+= String.Format(fmt, text)
                
ElseIf type = "natural" Then
                    query 
+= String.Format(" AND FREETEXT('{0}')", text)
                
End If

                query 
+= " ORDER BY Rank DESC"

                Return query
            
End Get
        
End Property

 

         '  如果网页没有Title,那么使用文件名
         Protected   Function GetTitle(ByVal value As ObjectAs Object
            
Dim title As String = Convert.ToString(DataBinder.Eval(value, "DocTitle"))

            
If Not (title Is NothingAnd title.Length > 0 Then
                
Return title '
            Else
                
Return DataBinder.Eval(value, "Filename")
            
End If
        
End Function
  ' GetTitle

        
'  取摘要
         Protected   Function GetCharacterization(ByVal value As ObjectAs String
            
Return Server.HtmlEncode(Convert.ToString(DataBinder.Eval(value, "Characterization")))
        
End Function


        
'  取文件尺寸,单位KB
         Protected   Function GetFileSize(ByVal value As ObjectAs String
            
Return Convert.ToString(CInt(Convert.ToInt32(DataBinder.Eval(value, "Size")) / 1000))
        
End Function


界面外观如下图:

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.luyixian.cn/news_show_883351.aspx

如若内容造成侵权/违法违规/事实不符,请联系dt猫网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

网站推荐机制中的艺术、科学与商务问题

网站推荐机制是电子商务或内容网站的核心功能之一。例如你在一个网站买了一本书后&#xff0c;网站会推荐其他你可能会感兴趣的书。这被认为是亚马逊等电子商务巨头成功的关键。本文对几个出色的推荐系统进行了较透彻的分析。 2006年10月&#xff0c;Netflix搞了一次不寻常的有…

OpenCms创建网站过程图解——献给OpenCms的初学者们

很多人都听说了OpenCms&#xff0c;知道了它的强大&#xff0c;索性的下载安装了&#xff0c;终于见到了久违OpenCms&#xff0c;看到了它简洁的界面&#xff0c;欣喜过后却不免一脸茫然&#xff0c;这个东西怎么用&#xff0c;我怎么用它来建站&#xff0c;从哪开始&#xff0…

Red Hat推出”MugShot”社交娱乐网站

网址: http://mugshot.org/ Red Hat近来推出”MugShot”网站, MugShot是一个致力于在线社交娱乐的开源项目. 它提供了更方便的网页和音乐分享. 当前MugShot处于测试阶段, 只提供邀请帐号. 你可以从这里申请. 更多信息见常见问题和开发主页. 欢迎任何问题和建议. 网址: http://…

ASP.NET 2.0网站专案同时使C#与VB.NET之技巧(新书连载)

ASP.NET 2.0网站专案同时使C#与VB.NET之技巧&#xff08;新书连载&#xff09; 你知道专案ASP.NET 2.0网站要如何同时使用C#与VB.NET两种语言及多组件的技巧吗&#xff1f; 节录自【圣殿祭司的ASP.NET 2.0专家技术手册】新书 在以往VS.NET 2002及VS.NET 2003的Visual Studio工具…

Coursera网站无法播放视频显示图片问题解决

Coursera网站无法播放视频显示图片问题解决 在线解析工具改变host文件cmd终端 因为最近在Coursera网站上学习吴恩达老师deep learning这门课程&#xff0c;但是我们在国内去上这个网站的时候其实是没有办法显示图片和视频的&#xff0c;因此在网上查阅相关内容之后&#xff0c;…

CSS制作简易花束网站首页(新手适用)

效果展示&#xff1a; 制作头部&#xff1a; 思路&#xff1a;在h1标题中加入颜色和不同字体大小等样式&#xff0c;在标题下加条下划线即可。 <header><h1><strong>浪漫の都</strong><em>___这一生只为与你相遇</em></h1><hr s…

在chrome中设置禁止访问的网站

如何在chrome中禁止访问某个网站&#xff1a; 点击右上角&#xff0c;一竖排点那个按钮&#xff1a; 2.选择“设置”&#xff1b; 3.左边选择“隐私与安全设置”&#xff1a; 4.选择网站设置最左边的小箭头&#xff1a; 5.点击这个&#xff1a; 6.找到禁止的地方&#…

PHP网站登录分发程序+无需申请登陆权限

简介&#xff1a; 申请一个Q互联登录权限后&#xff0c;可以分发给更多的网站使用&#xff0c;安装与配置请下载后打开readme.txt 发起登陆&#xff1a;域名/api.php?token&#xff0c;登陆之后会成功跳转到后台token对应的回调地址&#xff0c;会带着获取到openid回调。 下…

在线增加网站PV量单页源码

介绍: PV是什么想必想必站长们都知道是什么&#xff0c;所以我这里就不解释了&#xff0c;我看了下程序文件&#xff0c;核心文件是被加密的&#xff0c;但是不影响使用&#xff0c;加密类型是混淆加密&#xff0c;混淆加密是很好解的&#xff0c;如果你是在想要源文件&#x…

大型网站高并发处理Nginx+lvs

一.负载均衡 为啥会出现负载均衡 在海量并发的环境下&#xff0c;用户每一次请求服务器&#xff0c;都需要大量的创建线程&#xff0c;每一次的线程都必须分配资源&#xff08;CPU、内存、带宽、磁盘 IO等&#xff09;&#xff0c;当资源不足的时候就会使得服务器宕机而无法提…

“网络白痴”初学SEO成长经验心得

三个月前因为工作上的需要&#xff0c;开始接触网络知识。因为我的工作面对的是网站&#xff0c;负责对网站进行优化&#xff0c;所以在范围那么大的网络知识中只需要学习其中的一小部分就可以了。 网站优化在行业中叫做“seo”(Search Engine Optimization)汉译为搜索引擎优化…

我为什么要做个人网站——互联网乌托邦的理想

2019年3月6日夜&#xff0c;我在qq空间第一次公开我的个人网站。 这是我的第一个网站&#xff0c;不&#xff0c;现在它还不能算是一个网站&#xff0c;因为做好的&#xff0c;仅仅一个欢迎页面&#xff0c;而真正的网站&#xff0c;是要有更丰富的页面和内容的&#xff0c;这是…

电商网站--放大镜效果的实现

最近有做一个PC端的简单官网,主要是进行商品的展示,目前没有收藏,加入购物车,购买的功能,商品详情页有商品图片,各种详细信息的展示,原型上是没有放大镜的功能的,当时有空余时间,我就想着试试放大镜的效果吧,js可以实现,但是网上页有各种插件,不用白不用,那就用插件吧 // 1,,,…

编译安装nginx网站服务与虚拟主机配置

文章目录 一、Nginx简介二、编译安装Nginx&#xff0c;以及优化服务2.1、编译安装nginx2.1.1 xftp导入nginx依赖包2.1.2 yum安装依赖包2.1.3 解压软件包&#xff0c;并配置configure进行编译安装2.1.4 优化执行路径并创建不可登录的程序用户2.1.5 制作管理脚本 2.2 Nginx的访问…

一个小女孩是如何拯救全球第三大社交网站的?

很多互联网产品都从用户那里得到过很大的帮助&#xff0c;最基本的是用户会对自己使用的产品进行评论或者提出建议。但也有用户为自己喜爱的产品做出过巨大的贡献。 2008年印象笔记(Evernote)陷入了困境&#xff0c;账上的钱只够支撑三周。CEO Phil Libin 打算关掉这家公司。 就…

SNS是什么?有哪些类型的SNS网站?

SNS&#xff0c;全称Social Networking Services&#xff0c;即社会性网络服务&#xff0c;专指在帮助人们建立社会性网络的互联网应用服务。SNS若在互联网领域就有三层含义&#xff0c;他们的英文缩写分别是&#xff1a;服务 Social Network Service&#xff0c;软件 Social N…

Mysql在大型网站的应用架构演变

原创文章&#xff0c;转载请注明&#xff1a; 转载自http://www.cnblogs.com/Creator/ 本文链接地址: Mysql在大型网站的应用架构演变 本文已经被多处转载&#xff0c;包括CSDN推荐以及码农周刊等等,阅读数超过5w,回流到我博客流量的还是比较少,不过这不重要, 后续会分享更多技…

使用you-get将网站视频下载到本地的具体操作

周五&#xff0c;我朋友给我一个b站的链接。他想要下载里面的视频。但是电脑上的b站是没有提供下载功能的&#xff0c;身为程序员。当然得帮兄弟这个忙啦。 此次操作我们会用到两个小东西&#xff1a;you-get、ffmpeg you-get使用方法 电脑需要安装python。输入命令 pip3 in…

某网站首页双12 活动 banner主色调选择

文章目录 案例背景 1 检验指标的确定2 确定检验统计量3 埋点收集数据4 确定H0,H15 确定显著性水平6 计算样本量7 利用统计工具实现检验 案例背景 某网站首页双12 活动 banner主色调选择&#xff08;现提供两个版本的banner)&#xff0c; banner 为网站PC端或App 的顶部或底部横…

Hadoop环境中使用Hive工具实现电商网站用户运营分析

文章目录 一、分析目标二、数据说明三、实现步骤1.建立用户指标体系2.建立分阶段用户标签2.1 按用户行为统计每日的不同阶段用户规模2.2 按周为单位分析最近两周的不同阶段用户的变化2.3 对比分析新用户群体与激活用户群体的人群画像、行为数据特点 3、用户复购分析3.1 计算2月…