风讯官方论坛

首页 » FoosunCMS交流区 » Foosun3.x安装使用 » 添加新闻时自动添加关键字(附采集时自动添加关键字)
lino - 2005-10-17 20:06:00

我是先做抓取新闻时自动添加关键字后,想到手工添加新闻时也可以把这个功能用上去。所以两段程序可以说是完全一样的,只是应用的场所不同~


请先备份:


Admin/Info/NewsWords.asp


下面开始修改:


1、打开Admin/Info/NewsWords.asp,拉到倒数第二行(也就是%>的前面),把下面的代码贴上去。


'************************************
'author:lino
'把标题与关键字表中的记录匹配
'Start
'*************************
Function replaceKeywordByTitle(title)
Dim whereisKeyword,i,theKeywordOnNews
Dim keyword,rsRuleObj,theKeywordS


'**********如果3.1版,请把下行Routine改成FS_Routine
Set RsRuleObj = Conn.Execute("Select * from Routine")
do while Not RsRuleObj.Eof
  keyword = RsRuleObj("name")
  whereisKeyword = InStr(Lcase(title),Lcase(keyword))
  if(whereisKeyword>0) then 
  if(theKeywordOnNews="") then 
    theKeywordOnNews=keyword 
  else 
    theKeywordOnNews=theKeywordOnNews&","&keyword
  end if
  end if
  RsRuleObj.MoveNext
loop


'如果keyword的长度大于100,截去过长的
if(len(theKeywordOnNews)>99) then
  theKeywordOnNews=left(theKeywordOnNews,99)
end if

replaceKeywordByTitle = theKeywordOnNews
End function
'**********************
'End


在同一页面(即Admin/Info/NewsWords.asp)中找到


INewsAddObj("KeyWords") = Replace(Replace(Requst("KeywordText"),"""",""),"'","")
或约637行,把
INewsAddObj("KeyWords") = Replace(Replace(Requst("KeywordText"),"""",""),"'","")
换成
'************************************
'author:lino
'把调用replaceKeywordByTitle方法,过滤关键字
'如果用户自定义了关键字,自动设置关键字不起作用

'Start
'*************************
Dim KeywordText
if (Request("KeywordText")="" or isempty(Request("KeywordText"))) then
  KeywordText = replaceKeywordByTitle(ITitle)


else
  KeywordText = Request("KeywordText")
end if


if KeywordText <> "" then
  INewsAddObj("KeyWords") = Replace(Replace(KeywordText,"""",""),"'","")
end if

'End
'***********************************


OK!马上就能用了。


附:[源码分享]---采集新闻时,自动添加关键字---
http://bbs.foosun.net/dispbbs.asp?boardID=24&ID=12277&page=1


这个贴子里有关于这段程序的详细说明~


[此贴子已经被作者于2005-10-28 11:33:46编辑过]

hotla - 2005-10-17 20:07:00
好文是要加精的.哈哈
hotla - 2005-10-17 20:11:00

已收录


http://www.94bang.com/help/artifice/index.htm

tuzi15 - 2005-10-17 21:01:00




好文
[em04]
lino - 2005-10-17 22:06:00
谢谢大哥支持~
doudou888 - 2005-10-18 06:43:00

收藏,非常谢谢!!

zhzdh401 - 2005-10-18 07:09:00
好!!!
lino - 2005-10-18 08:08:00
对于想在文字新闻和图片新闻中都加上该功能的兄弟,建议把

'************************************
'author:lino
'把标题与关键字表中的记录匹配
'Start
'*************************
Function replaceKeywordByTitle(title)
Dim whereisKeyword,i,theKeywordOnNews
Dim keyword,rsRuleObj,theKeywordS
Set RsRuleObj = Conn.Execute("Select * from Routine")
do while Not RsRuleObj.Eof
  keyword = RsRuleObj("name")
  whereisKeyword = InStr(Lcase(title),Lcase(keyword))
  if(whereisKeyword>0) then 
  if(theKeywordOnNews="") then 
    theKeywordOnNews=keyword 
  else 
    theKeywordOnNews=theKeywordOnNews&","&keyword
  end if
  end if
  RsRuleObj.MoveNext
loop


'如果keyword的长度大于100,截去过长的
if(len(theKeywordOnNews)>99) then
  theKeywordOnNews=left(theKeywordOnNews,99)
end if

replaceKeywordByTitle = theKeywordOnNews
End function
'**********************
'End

这一段加到Function.asp的倒数第二行里,把NewsPic.asp的
INewsAddObj("KeyWords") = Replace(Replace(Requst("KeywordText"),"""",""),"'","")
换成
'************************************
'author:lino
'把调用replaceKeywordByTitle方法,过滤关键字
'如果用户自定义了关键字,自动设置关键字不起作用
'Start
'*************************
Dim KeywordText
if (Request("KeywordText")="" or isempty(Request("KeywordText"))) then
  KeywordText = replaceKeywordByTitle(ITitle)


else
  KeywordText = Request("KeywordText")
end if


if KeywordText <> "" then
  INewsAddObj("KeyWords") = Replace(Replace(KeywordText,"""",""),"'","")
end if

'End
'***********************************


就行了


[此贴子已经被作者于2005-10-18 8:08:27编辑过]

yuanis - 2005-10-18 10:05:00

用了,很爽


能不能把原来生成的数据也都自动加上关键字

lino - 2005-10-18 11:03:00

想过,但没做~因为原先的数据有可能是手工指定的关键字,精确度要比自动生成的高。这种情况下自动生成关键字会带来一些问题~



[此贴子已经被作者于2005-10-18 11:04:01编辑过]

arrok - 2005-10-28 00:24:00

为何我修改的却不能自动添加关键字呢?!


郁闷.


另:大哥有一个单词书写错误


INewsAddObj("KeyWords") = Replace(Replace(Requst("KeywordText"),"""",""),"'","")


Request


----------


能否将你整理的文件打外包呢?!我严格按照你书写的方法,却能自动添加.关于采集那篇贴子.我也看了...对照着做完后.还在采集的数据库的NEWS表里加上了keywords字段也没OK...不解.

[em49][em49][em49]
阿朱 - 2005-11-24 18:14:00
晕,我还以为是我错误了,原来发现只针对与标题才可以?为什么不改一改可以针对新闻内容呢?试问一下标题能与关键字匹配会有多少》?
yj999 - 2005-11-24 21:46:00
这个可能是3.1不行了吧?
yj999 - 2005-11-24 22:37:00
3.1找不到那些代码呀。
潮儿 - 2006-3-11 10:21:00
有没有支持新版的呢??
yztschq - 2006-4-13 07:59:00
[em01][em01][em01]
sxyzy - 2006-4-24 14:33:00
需要支持新版本的???
××× - 2006-6-9 10:26:00
能支持3.2 SP1就好了
ssff6688 - 2006-6-9 11:36:00
支持新版3.2就好了
1891 - 2006-7-28 17:35:00
做个记号!
storein - 2006-7-29 19:18:00

不错。

支持

 

 

 

触摸屏
yxwf2008 - 2006-10-12 17:49:00

用不着

ah8 - 2008-1-26 14:10:00
sp5 可以吗
1
查看完整版本: 添加新闻时自动添加关键字(附采集时自动添加关键字)