PostgreSQL、PHP - 如何设计数据库搜索?
我需要设计一个搜索表单及其背后的代码。
我对搜索不是很熟悉。
我的表格有以下几个方面:
- Table_ads
site_name
ad_type
uri
pagetitle
name_ad
general_description_ad
age
country_ad
location_ad
zone_ad
最初我的想法是像谷歌一样进行搜索,我们有一个文本框和按钮搜索,但我认为这会很困难。另一种选择是按字段建立搜索(传统搜索)
您对此主题有何看法。我应该进行什么类型的搜索?
最好的问候,
PS:对不起我的英语。
I need to design a search form and the code behind it.
I'm not very familiar with searches.
My table have the following aspect:
- Table_ads
site_name
ad_type
uri
pagetitle
name_ad
general_description_ad
age
country_ad
location_ad
zone_ad
Initially my idea was to do a search like google, we have a single text box and the button search, but I think this will be difficult. The other option is to build a search by fields(traditional search)
What do you think about this subject. What type of search should I do?
Best Regards,
PS: Sorry my English.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对于“类似 google”的搜索,最好使用全文搜索 (FTS) 解决方案。
PostgreSQL 8.3 及更高版本有一个内置的 FTS 引擎,它可以让您在 SQL 中完成所有查询。示例:
参见文档 -> http://www.postgresql.org/docs/current/static/textsearch.html 如果您有更多问题,请回来 :-)
但是,数据库内 FTS 比专用 FTS 慢几倍。
所以如果你需要更好的性能,你将不得不在数据库之外建立一个索引,
这里我会推荐Sphinx -> http://sphinxsearch.com/docs/current.html,Sphinx 与 PHP 顺利集成。您可以向其提供文档(最好以特殊 XML 文档集的形式)并根据需要或使用某些调度程序更新索引。然后直接从 PHP 进行搜索(不接触数据库)。
HTH。
For "google-like" search it's best to use Full-Text Search (FTS) solution.
PostgreSQL 8.3 and newer has a built-in FTS engine, and it will let you do all querying in SQL. Example:
See documentation -> http://www.postgresql.org/docs/current/static/textsearch.html and come back if you have more questions :-)
However, in-database FTS is several times slower than dedicated FTS.
So if you need better performance, you will have to build an index outside of database,
Here I would recommend Sphinx -> http://sphinxsearch.com/docs/current.html, Sphinx integrates smoothly with PHP. You feed it with documents (preferably, in form of special XML docset) and update the index on demand or with some scheduler. Then you do searching directly from PHP (not touching the database).
HTH.