如何使用FULLTEXT搜索返回所有字段? [英] How to return all fields with FULLTEXT search?

查看:77
本文介绍了如何使用FULLTEXT搜索返回所有字段?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此问题与>全文搜索在搜索时不起作用确切的标题

我正在尝试学习如何有效地搜索数据库,并且遇到了FULLTEXT搜索,这似乎是最好的选择.由于目前我尚未收集大量数据,因此我的表仍然很小.我有将搜索表的此sql代码

I'm trying to learn how to search databases efficiently, and came across FULLTEXT searches which seem to be the best option. My tables are still small at this point as I haven't collected a lot of data yet. I had this sql code that would search the table

SELECT * FROM table WHERE MATCH(title) AGAINST ('hamlet') LIMIT 30;

但是由于只有一行,它什么也没返回.允许查询返回信息的解决方法是什么?

but since there's only one row, it returned nothing. What would be some workarounds, to allow the query to return the info?

谢谢

推荐答案

这就是我要做的:

SELECT title ,
MATCH(title) 
AGAINST ('hamlet' IN BOOLEAN MODE)
AS relevance 

FROM test 
WHERE  MATCH(title) 
AGAINST ('hamlet' IN BOOLEAN MODE) 

HAVING relevance > 0 ORDER BY relevance DESC

使用的表:

CREATE TABLE IF NOT EXISTS `test` (
  `id` tinyint(4) NOT NULL,
  `title` varchar(255) collate utf8_unicode_ci NOT NULL,
  PRIMARY KEY  (`id`),
  FULLTEXT KEY `name_2` (`title`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

--
-- Dumping data for table `test`
--

INSERT INTO `test` (`id`, `title`) VALUES
(2, 'hamlet');

这篇关于如何使用FULLTEXT搜索返回所有字段?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆