如何在网站中实现搜索功能? [英] How do I implement Search Functionality in a website?

查看:83
本文介绍了如何在网站中实现搜索功能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想为网站实现搜索功能(假设它类似于 SO).我不想使用 Google 搜索此类内容.

I want to implement search functionality for a website (assume it is similar to SO). I don't want to use Google search of stuff like that.

我的问题是:

我该如何实施?

我知道有两种方法:

  1. 在用户提出查询时搜索应用程序中的所有数据库.
  2. 索引我拥有的所有数据并将其存储在其他地方并从那里查询(就像 Google 所做的那样).

谁能告诉我该走哪条路?有什么优点和缺点?

Can anyone tell me which way to go? What are the pros and cons?

更好,有没有更好的方法来做到这一点?

Better, are there any better ways to do this?

推荐答案

使用 lucene,
http://lucene.apache.org/java/docs/

Apache Lucene 是一个高性能、全功能的文本搜索引擎库,完全用 Java 编写.这是一项适用于几乎所有需要全文搜索的应用程序的技术,尤其是跨平台的应用程序.

Apache Lucene is a high-performance, full-featured text search engine library written entirely in Java. It is a technology suitable for nearly any application that requires full-text search, especially cross-platform.

它在 java 和 .net 中可用.它也可以在 php 中以 Zend 框架模块的形式使用.

It is available in java and .net. It is also in available in php in the form of a zend framework module.

Lucene 做你想做的事(搜索项目的索引),你必须跟踪一个 lucene 索引,但在性能方面它比做数据库搜索要好得多.顺便说一句,SO 搜索由 lucene 提供支持.:D

Lucene does what you wanted(indexing of the searched items), you have to keep track of a lucene index but it is much better than doing a database search in terms of performance. BTW, SO search is powered by lucene. :D

这篇关于如何在网站中实现搜索功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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