如何做全文检索? select text from abc where %'aaa'%;用匹配符号不就可以了吗?! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 通常来说,用这是数据库的问题。在SQL Server中,如果对某一张表的某个文本字段做了全文索引就可以实现。比如,对Books表的BookName(nvarchar(100))、Comments(ntext)字段设置了全文索引,那么用类似:select * from Books where contains(Comments, "优秀")的SQL就可以找到符合条件的记录。contains只是其中之一,还有其它函数。买一本SQL Server的书,都会讲到。 如果要进行查询关键字加亮的话,有专门的函数:php:str_replace,其他的编程语言类似! 程序中输出数据之前替换掉关键字嘛用<font color=red>关键字</font>替换关键字不就行了 感谢各位!不过我最终的结果是要将这篇文章在网页上输出,如何在输出之前将其中的关键字<font color=red>关键字</font>插进去呢?烦请各位指教! 先定义replace: private String replace(String news, String old, String newstr) { StringBuffer sb = new StringBuffer(); int pos = 0; int last = 0; pos = news.indexOf(old, last); while ( pos > 0 ) { sb.append(news.substring(last, pos)); sb.append(newstr); last = pos + old.length(); pos = news.indexOf(old, last); } sb.append((news.substring(last, news.length()))); return sb.toString(); }然后:text = "文章内容......."; result = replace(text,"关键字", "<font color=red>关键字</font>"); 上法无法检索第一个字符,应该为:private String replace(String news, String old, String newstr) {StringBuffer sb = new StringBuffer();int pos = 0;int last = 0;pos = news.indexOf(old, last);if (pos==0){sb.append(newstr);last = pos + old.length();pos = news.indexOf(old, last);}while ( pos > 0 ) {sb.append(news.substring(last, pos));sb.append(newstr);last = pos + old.length();pos = news.indexOf(old, last);}sb.append(news.substring(last, news.length()));return sb.toString();} 在java语言中,真的没有指针吗? java窗口根据全局变量自动变化的问题 初学java,自己写的计算器 String 类型的时间格式转换 求一字符替换的正则表达式!!!!!!!!!!! 越简单越好!`~~~ 写一个方法判断两个矩形在二维空间中是否相交 java条件表达式判断 高分求教关于jCheckBox[i]的问题 初到JAVA,请多关照!——请问applet和beans的区别? 关于TagLib的问题 怎样在一个文件中查找一个字符串? 询问学习方向
在SQL Server中,如果对某一张表的某个文本字段做了全文索引就可以实现。
比如,对Books表的BookName(nvarchar(100))、Comments(ntext)字段设置了全文索引,那么用类似:
select * from Books where contains(Comments, "优秀")
的SQL就可以找到符合条件的记录。
contains只是其中之一,还有其它函数。买一本SQL Server的书,都会讲到。
php:str_replace,其他的编程语言类似!
用<font color=red>关键字</font>替换关键字不就行了
不过我最终的结果是要将这篇文章在网页上输出,如何在输出之前将其中的关键字<font color=red>关键字</font>插进去呢?
烦请各位指教!
private String replace(String news, String old, String newstr) { StringBuffer sb = new StringBuffer(); int pos = 0;
int last = 0;
pos = news.indexOf(old, last);
while ( pos > 0 ) { sb.append(news.substring(last, pos));
sb.append(newstr); last = pos + old.length(); pos = news.indexOf(old, last);
} sb.append((news.substring(last, news.length()))); return sb.toString();
}然后:
text = "文章内容.......";
result = replace(text,"关键字", "<font color=red>关键字</font>");
private String replace(String news, String old, String newstr) {StringBuffer sb = new StringBuffer();int pos = 0;
int last = 0;
pos = news.indexOf(old, last);
if (pos==0)
{sb.append(newstr);
last = pos + old.length();
pos = news.indexOf(old, last);
}
while ( pos > 0 ) {sb.append(news.substring(last, pos));
sb.append(newstr);last = pos + old.length();pos = news.indexOf(old, last);
}sb.append(news.substring(last, news.length()));return sb.toString();
}