首页 新闻 会员 周边 捐助

如何实现数据库多关键字搜索

0
悬赏园豆:50 [已关闭问题]
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span style="font-family: 宋体; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;"><span style="font-size: small;">具体要求,能处理以下几种搜索字符串:</span></span></p> <p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span style="font-size: small;"><span lang="EN-US"><span style="font-family: Calibri;">1</span></span><span style="font-family: 宋体; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">.</span><span lang="EN-US"><span style="font-family: Calibri;">&rdquo;</span></span><span style="font-family: 宋体; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">关键字</span><span lang="EN-US"><span style="font-family: Calibri;">&rdquo;</span></span><span style="font-family: 宋体; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">。要求能够返回匹配该串的所有结果。</span></span></p> <p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span style="font-size: small;"><span lang="EN-US"><span style="font-family: Calibri;">2</span></span><span style="font-family: 宋体; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">.&ldquo;关键字</span><span lang="EN-US"><span style="font-family: Calibri;">1<span style="mso-spacerun: yes;">&nbsp; </span></span></span><span style="font-family: 宋体; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">关键字</span><span lang="EN-US"><span style="font-family: Calibri;">2</span></span><span style="font-family: 宋体; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">&rdquo;</span><span style="font-family: Calibri;"> </span><span style="font-family: 宋体; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">相当于在数据库中进行如下的关键字检索并按下列优先级顺序返回搜索结果</span><span lang="EN-US"><span style="font-family: Calibri;">:</span></span></span></p> <p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span style="font-size: small;"><span lang="EN-US"><span style="font-family: Calibri;">(1) </span></span><span style="font-family: 宋体; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">&ldquo;关键字</span><span lang="EN-US"><span style="font-family: Calibri;">1<span style="mso-spacerun: yes;">&nbsp; </span></span></span><span style="font-family: 宋体; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">关键字</span><span lang="EN-US"><span style="font-family: Calibri;">2</span></span><span style="font-family: 宋体; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">&rdquo;</span></span></p> <p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span style="font-size: small;"><span lang="EN-US"><span style="font-family: Calibri;">(2) </span></span><span style="font-family: 宋体; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">&ldquo;关键字</span><span lang="EN-US"><span style="font-family: Calibri;">2<span style="mso-spacerun: yes;">&nbsp; </span></span></span><span style="font-family: 宋体; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">关键字</span><span lang="EN-US"><span style="font-family: Calibri;">1</span></span><span style="font-family: 宋体; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">&rdquo;</span></span></p> <p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span style="font-size: small;"><span lang="EN-US"><span style="font-family: Calibri;">(3) </span></span><span style="font-family: 宋体; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">&ldquo;关键字</span><span lang="EN-US"><span style="font-family: Calibri;">1</span></span><span style="font-family: 宋体; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">&rdquo;</span></span></p> <p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span style="font-size: small;"><span lang="EN-US"><span style="font-family: Calibri;">(4) </span></span><span style="font-family: 宋体; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">&ldquo;关键字</span><span lang="EN-US"><span style="font-family: Calibri;">2</span></span><span style="font-family: 宋体; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">&rdquo;</span></span></p> <p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span style="font-size: small;"><span style="font-family: 宋体; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">比如搜&ldquo;博客园 架构&rdquo;</span></span></p> <p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span style="font-size: small;"><span style="font-family: 宋体; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">那么类似下面这四个匹配串,(1)的返回优先级最高,(4)最低</span></span></p> <p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span style="font-size: small;"><span style="font-family: 宋体; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">(1)"%博客园%架构%"</span></span></p> <p><span style="font-size: small;"> <p><span style="font-family: 宋体; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;"> <p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span style="font-size: small;"><span style="font-family: 宋体; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">(2)"%架构%博客园%"</span></span></p> </span></p> </span></p>
问题补充: (3)'%博客园%' (4)'%架构%'
父辈的旗帜的主页 父辈的旗帜 | 初学一级 | 园豆:2
提问于:2008-12-02 13:55
< >
分享
其他回答(7)
0

编写一个存储过程,定义两个关键字变量,然后定认查询语句把你上面的两个条件用OR连起来.根据传入的关键字进行组合.这样行不?

Astar | 园豆:40805 (高人七级) | 2008-12-02 14:17
0
玉开 | 园豆:8822 (大侠五级) | 2008-12-02 15:16
0

一楼组合多个查询的办法倒是可行,就是这个效率……怕是很差,尤其你是在文本里like '%xx'

二楼全文索引效率倒是可以,可是那个优先级怕是没有那么容易排,如果不嫌服务器累,可以使用全文索引把所有的都取出来,由程序来排列优先级顺序

这种搜索,想完美解决~~~数据库怕是无能为力,超出数据库的能力范围了~~~~~

丁学 | 园豆:18730 (专家六级) | 2008-12-02 16:47
0

这个问题去问问百度,百度的竞价排名就是谁给的钱多谁排在前面,和这个有相同的地方

上不了岸的鱼 | 园豆:4613 (老鸟四级) | 2008-12-02 18:04
0

同意丁学的,这个数据库无能为力

在程序级别上分别取出各个优先级的内容,再加以组合展示

LanceZhang | 园豆:857 (小虾三级) | 2008-12-03 17:56
0

上不了岸的鱼{ttzhang}的答案比较经典..但是解决不了问题...

感觉这应该属于搜索引擎的事情,如果数据库能拿来做了,那程序还干吗???

有所为,有所不为 | 园豆:1200 (小虾三级) | 2008-12-04 11:19
0

数据库可以解决排序问题。只是效率低得可怜(等到你哭!!)。

用Union    

示例:(select * from table1 where filedName like "%博客园%架构%" ) union (select * from table2 where filedName like "%架构%博客园%" and id not in (select id from ....) )union.....

不写了,不忍心写了。我听到CPU在哭。。。

就这个思路。。。。。如果数据量大的话一天查个几次应该差不多了吧。。。如果你要完美的解决方案可以研究一下搜索引擎~研究一下Lucene.

BB_Coder | 园豆:797 (小虾三级) | 2008-12-09 13:14
0

还是去研究下SEO吧。。。。。。。

sl2008 | 园豆:407 (菜鸟二级) | 2008-12-11 11:04
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册