cms
当前位置:首页->使用帮助
搜索引擎在Asp Cms下的应用
  • 作者:本站
  • 日期:2010-04-26
  • 出处:totcms
  • 点击:575

1、首先下载站内搜索引擎,首先要导入CMS中的数据到搜索引擎索引中,这个工作您可以放到本地来做,索引后,直接将搜索引擎文件夹压缩后上传到您的空间上即可。

2、数据索引说明:

3、首先在本地部署一个asp.net环境,然后安装站内搜索引擎,假如访问地址是:http://localhost。

4、下面输入地址:http://localhost/reset.aspx 进行数据库的索引初始化,见下图:

如上图所示,填写好CMS数据库连接字符串,点击“连接数据库”,提示成功后,可以看到“选择索引的表”下拉框中有许多表,选择CMS内容存放的表:news,然后在“当前表中的字段”可以看到news表中的字段记录,这是为我们方便左侧的字段映射填写而显示。

5、目前站内搜索引擎提供了8个索引字段,分别是:ID,标题、栏目ID、缩略图、摘要、详细内容、修改日期、链接地址,然后我们根据news表中的字段情况,填写对应搜索引擎中的字段名称,如上图所示。

6、字段对应填写好以后,点击“开始执行索引”,根据您数据库中文章数量的不同情况,因为软件将执行文章内容的分词、索引操作,花费一定的时间后,就完成了搜索引擎的数据索引工作。

7、输入网址http://localhost 测试数据查询情况。可以看到数据库中的内容已索引到站内搜索引擎中了

8、接口的增加

打开CMS文件夹,找到admin/news_add_ok.asp

在第235行的:call add_data(file_path) 后面增加一行,代码如下:

 ''''''''''''''''''''''
'参数配置
''''''''''''''''''''''
Const SearchPortal="http://localhost/totindex.aspx" '搜索引擎索引接口地址
Const IndexKey="totsearchengine01"   '接口访问key,请通过搜索引擎中的web.config查找
'==================================================================
'提交数据
'==================================================================
Function PostHttpPage(loginUrl,loginActUrl,PostData,CharSets)
    Dim xmlHttp
    Dim RetStr     
    Set xmlHttp = CreateObject("Microsoft.XMLHTTP") 
    xmlHttp.Open "POST", loginActUrl, False
    XmlHTTP.setRequestHeader "Content-Length",Len(PostData)
    xmlHttp.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
   ' xmlHttp.setRequestHeader "Referer", loginUrl
    xmlHttp.Send PostData
    If Err.Number <> 0 Then
        Set xmlHttp=Nothing
    response.Write("提交出错!提交数据:"&PostData)
        Exit Function
    End If
    PostHttpPage=BytesToBstr(xmlHttp.responseBody,CharSets)
    Set xmlHttp = nothing
End Function

'========================================================================
'字符编码函数
'========================================================================
Function BytesToBstr(body,code)
 dim objstream
 set objstream = Server.CreateObject("adodb.stream")
 objstream.Type = 1
 objstream.Mode =3
 objstream.Open
 objstream.Write body
 objstream.Position = 0
 objstream.Type = 2
 objstream.Charset =code
 BytesToBstr = objstream.ReadText 
 objstream.Close
 set objstream = nothing
End Function
dim ret
'添加索引
dim indexid
set rs=conn.execute("select top 1 id from news order by id desc")
if not rs.eof then
 indexid=rs(0)
else
 indexid=1
end if
ret=PostHttpPage(SearchPortal,SearchPortal,"key="&IndexKey&"&action=insert&id="&indexid&"&Title="&title&"&Content="&content&"&Categoryid="&newsclass&"&Summary="&content&"&Photo="&photo&"&ModDate="¤t_time&"&LinkUrl="&SiteUrl&"/"&file_path&"","utf-8")
response.Write(ret)
response.Write("
")

下载附件:news_add_ok.rar