[原创]
主要代码示意如下(c#版):
key为用户输入的内容
keywords为数据库的词库表
sql为数据查询语句
order为数据排序语句
words为要查的所有字段链接后的结果
conn为数据库操作类实例
//找出所有符合用户输入内容的关键字
dw=conn.Select("select title from keywords where '"+key+"' like '%'+title+'%' and act="+act1);
//循环
for(i=0;i<dw.Rows.Count;i++)
{
word=dw.Rows[i][0].ToString();
sql+=" or "+words+" like '%"+word+"%'";
order+="+(case CHARINDEX('"+word+"',"+words+") when 0 then 1000 else CHARINDEX('"+word+"',"+words+") end)";
}
词库产生代码
ppp为1是查询 分页或刷新后就不是1了
if(ppp=="1")
{
try
{
ds=conn.Select("select id from keywords where title='"+key+"' and act="+act1);
if(ds.Rows.Count<1)
htc=conn.Update("insert into keywords (title,act) values('"+key+"',"+act1+")");//添加关键词,默认搜索1次
else
htc=conn.Update("update keywords set htc=htc+1 where id="+ds.Rows[0][0].ToString());//被搜索率+1
}
catch
{}
}
分词不是很难 难得是不仅是分词 有时候不分才难做呢
我觉得应该是这样的:
key=replace(replace(replace(replace(replace(replace(replace(request(keywords)," ","")," ","")," ","")," ","")," ","")," ","")," ","") '尽可能把多余的空格替换掉
words=split(request(keywords)," ") '把输入的关键字按空格断成书组
sql="select * from table where 字段 like '%"&key&"%'" '先给一个条件 什么条件都行
for i= 0 to ubound(words) '把数组循环取出
sql=sql&" or 字段 like '%"&words(i)&"%'"
next
rs.open sql,conn,1,1
这样就可以了!