搜索功能

发布于 2024-11-17 11:19:38 字数 166 浏览 0 评论 0原文

我正在构建一个简单的搜索工具。

这个想法是它将搜索代码、标题、描述和类别字段。

搜索类别和代码非常简单,因为它只是一个单词 (%code%)。

但是,我不确定如何分解标题和描述来搜索用户输入的任何关键字?

有人有这方面的好技术吗?

谢谢。

I am building a simple search facility.

The idea is that it will search the fields of code, title, description and category.

It's quite simple to search for the category and code as it's just one word (%code%).

However, I am unsure how I would break down the title and description to search for any keywords the user enters?

Does anyone have any good techniques for this?

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

谁许谁一生繁华 2024-11-24 11:19:38

鉴于信息量很少:

如果您使用 MySQL 中的 MyISAM 存储,您可以启用 FULLTEXT 索引并对其使用 FULLTEXT 搜索;有关详细信息,请参阅此链接

但是,如果您使用 InnoDB(我也在我的数据库上使用它),则无法直接在 MySQL 中启用它。

你有几个选择;您可以自己拆分关键字并搜索与一个或多个关键字匹配的条目,然后检查有多少个关键字与排序匹配。您还可以将其包含在查询中,但是您需要对每个关键字进行查询并将这些结果与父查询合并。

另一个选项,也是我最终选择的选项,因为性能和灵活性,是使用 SOLR 服务器并使用 php solr_client (参见 有关它的 php 手册)。 SOLR 服务器将在给定一些(相当简单)配置文件的情况下对数据库进行索引,并允许对任何索引字段进行全文搜索。有关设置 SOLR 服务器的更多信息,请参阅 SOLR 手册:教程

当然,还有许多其他方法和工具。以上只是我过去使用过或仍在使用的一些(我真的很高兴使用 solr,但我想这是个人的事情)。

祝你好运。

Given the little amount of info:

If you're using the MyISAM storage from MySQL you can enable FULLTEXT indexes and use a FULLTEXT search over that; see this link for more information on that.

If you're, however, using InnoDB (which I'm also using on my databases), you can't directly enable it in MySQL.

You have a few options; either you split up the keywords yourself and search for entries matching one or more of those keywords and check afterwards how many keywords matched for the ordering. You can also include that in the query, but then you'd need to make a query for each keyword and combine those results with a parent query.

Another option, which is the option I finally chose because of the performance and flexibility, is to use a SOLR server and use the php solr_client (see the php manual on it). The SOLR server will index the database given a few (fairly simple) configuration files and allow fulltext searches on any indexed field. More info about setting up a SOLR server can be found in the manual for SOLR: tutorial.

There are, ofcourse, many many other methods and tools. The above are just a few that I've used in the past or am still using (I'm really happy using solr, but that's something personal, I guess).

Good luck.

蓝眼泪 2024-11-24 11:19:38

你想要的东西MySQL 做的不是很好。 Yhn 提到了一些选择。

MySQL 的 FULLTEXT 索引不受欢迎是有充分理由的。

将文本分解为关键字并形成链接回原始项目的索引表是可行的。但这样做本质上就像开始构建自己的搜索引擎一样。

可以使用比您可能构建的更好的搜索引擎。 Yhn 提到了 SOLR,这非常好,但我还想提一下 Sphinx Search,我用的。 SOLR 有一些 Sphinx 没有的有趣功能,但我的印象是 Sphinx 更容易学习和上手。值得您考虑。

What you want is not something MySQL does very well. Yhn mentioned some options.

MySQL's FULLTEXT indexes are not popular for good reasons.

Breaking your texts down to keywords and forming indexed tables of them that link back to the original items can work. But doing that, in essence, is like starting to build your own search engine.

Much better search engines than you are likely to build are available. Yhn mentioned SOLR, which is very good, but I want to mention also Sphinx Search, which I use. SOLR has some interesting features that Sphinx doesn't have, but I had the impression Sphinx is easier to learn and get started with. It's worth your consideration.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文