精通
英语
和
开源
,
擅长
开发
与
培训
,
胸怀四海
第一信赖
When I was working on my first ever blog engine (sorry about this shameful self-promotion) recently, at the very late stage, I discovered a problem -- there is no search capability in this blog engine. I released it out on Digital Ocean as my personal photography site. But I regretted the decision of not having the search function in the application.
最近,当我第一次写博客引擎 (抱歉这可耻的自我推销) 时,在很晚的阶段,发现了一个问题 — — 这个博客引擎有没有搜索功能。我把博客引擎公开到Digital Ocean作为我的个人图片网站。但我感到遗憾的是决定不加入搜索功能。
For my own benefit, I decided to research for a solution to add full text search to the web app. It turned out that there are several approaches available. The obvious two for me are:
为了自己的利益,我决定研究一种添加到 web 应用程序的全文搜索解决方案。原来有几种方法可用。两个对我来说是显而易见的事实:
I highly recommended not trying the first approach because it is not portable. Here is the thing, if you follow this approach, you are making a tight couple of your application to a specific relational database. In the event of changing to a different database, you must implement a new dialect.
我强烈建议不用第一种方法,因为它不可移植。还有件事,如果你遵循这种方法,你就和一个特定的关系数据库紧密绑定。一旦更改到不同的数据库,您必须实现一种新方言。
Based on this reasoning, I chose the second approach which was quite a popular approach based on the search results I have received through Google. Regardless of the approaches, I still find it hard to get some good documentations on the type of integration I worked on. This article is intended to track all the information and give the audience a good working copy of the work I have done.
基于这种推理,我选择第二种方法,这是相当流行的方法,基于我收到通过谷歌的搜索结果。无论用何方法,我还是发现很难找得到一些好的文献。这篇文章旨在跟踪所有信息,并给观众提供我的工作副本。
Before I get into the details of how the implementation goes, I would like to discuss in brief the technologies I have used for this. The project is a Spring MVC based web application. I used Spring 3 components. The build is done using maven 2. The persistence layer is using Hibernate 4. The back end data store is MySQL. Everything is integrated through Spring.
在进入如何实现的细节之前,我想简要讨论用到的技术。该项目是基于web 应用程序的Spring MVC 。我用的Spring 3 组件。生成使用 maven 2。持久层使用Hibernate 4。后端数据存储是 MySQL。一切都通过Spring集成。
The attached zip file will have all you need to run the web app. What you need to do are: 附带的 zip 文件将有所有你需要运行的 web 应用程序。你需要做的:
Alternatively, you can use Maven to generate the Eclipse project files and import the project into Eclipse for editing. I even run the server in Eclipse for trouble shooting. The main focus of this article is to describe how the implementation of full text search on SQL based DB works, so I will not spend time explaining how to setup the dev environment for this. There are plenty of resources to help you with this problem.
或者,你可以使用 Maven 生成 Eclipse 项目文件并将该项目导入到 Eclipse 进行编辑。我甚至在 Eclipse 中运行服务器,用于故障排除。这篇文章的主要焦点是描述如何基于的 SQL 全文搜索实现 DB 的作品,所以我不会在此花时间来解释如何设置开发环境。有很多资源来帮你解决这个问题。
I will discuss the project architecture and code structure in detail. First, let me describe what this application does. It is a simple web based application. It allows the user to enter the details of a book: title, description, and author. And it allows the user to search the entered information by 1 simple keyword. As you can see, it is so simple and it does not do much. This is intended. All I want to show you is how to setup the whole thing. How you like to implement full text search functionality using Hibernate Search is up to you to do. Let's go through the steps on setting up this Java project.
我将讨论中详细的项目架构和代码结构。首先,让我描述此应用程序的执行。它是一个基于 web的简单应用程序。它允许用户输入的一本书的详细信息: 标题、 说明和作者。它允许用户通过 1 简单的关键字搜索输入的信息。正如你所看到的就这么简单,它并没有多大。这被为了。如何设置整件事是所有我想要给你看。你怎样想实现全文搜索功能使用Hibernate搜索是由你来做。让我们去通过设置此 Java 项目的步骤。
In the zip file, there is a folder called DB, which contains 2 scripts. The first script creates a DB user. The content looks like this:
在 zip 文件中,还有一个名为 DB,包含 2 脚本文件夹。第一个脚本创建一个数据库用户。内容看起来像这样:
CREATE DATABASE fulltextsearch; CREATE USER 'ftuser1'@'localhost' IDENTIFIED BY '123test321'; GRANT ALL PRIVILEGES ON fulltextsearch.* TO 'ftuser1'@'localhost'; FLUSH PRIVILEGES;
Run the above script on MySQL with root user, you will create a new user and new database for this project.
使用根用户对 MySQL 运行上面的脚本,您将创建一个新用户和新数据库为这个项目。
Another SQL script is included which will create a new table in the new DB. The content looks like the following:
另一个 包括在内SQL 脚本,将会在新数据库中创建一个新表。内容如下所示:
use fulltextsearch; DROP TABLE IF EXISTS book; CREATE TABLE book ( id VARCHAR(37) NOT NULL PRIMARY KEY, title VARCHAR(128) NOT NULL, description VARCHAR(256) NOT NULL, author VARCHAR(64) NOT NULL, createdate DATETIME NOT NULL, updatedate DATETIME NOT NULL );
Again, I won't explain how you will run these two scripts. There should be plenty of resources online to help you out.
再一次,我不会解释你将如何运行这两个脚本。应该有大量的在线资源,为您排忧解难。