Lucene4.0 Demo部署

Lucene4.0自带的Demo存在bug,本文描述如何部署Demo。

前提条件:安装了JDK、Tomcat、Eclipse (EE),下载了Lucene 4.0压缩文件和源码文件。

1. 在Eclipse忠创建一个Dynamic Web Project

2. 将lucene-4.0.0-src\lucene-4.0.0\demo\src\java文件夹中的内容复制到Eclipse工程的src目录下

3. 将lucene-4.0.0-src\lucene-4.0.0\demo\src\resources\org\apache\lucene\demo\xmlparser中的内容覆盖Eclipse工程的WebContent文件夹中的内容

4. 将lucene-analyzers-common-4.0.0.jar、lucene-core-4.0.0.jar、lucene-queries-4.0.0.jar、lucene-queryparser-4.0.0.jar、lucene-sandbox-4.0.0.jar复制到Eclipse工程的WebContent\lib文件夹中

5. 修改Eclipse工程的WebContent\WEB-INF\web.xml文件,修改内容为红色部分:

<?xml version="1.0" encoding="UTF-8"?>
<!--
 Licensed to the Apache Software Foundation (ASF) under one or more
 contributor license agreements.  See the NOTICE file distributed with
 this work for additional information regarding copyright ownership.
 The ASF licenses this file to You under the Apache License, Version 2.0
 (the "License"); you may not use this file except in compliance with
 the License.  You may obtain a copy of the License at

     http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
-->
<web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
	<display-name>
	LuceneXmlQueryWebDemo</display-name>
	<servlet>
		<description>
		Servlet demonstrating XMLQueryParser</description>
		<display-name>
		FormBasedXmlQueryDemo</display-name>
		<servlet-name>FormBasedXmlQueryDemo</servlet-name>
		<servlet-class>org.apache.lucene.demo.xmlparser.FormBasedXmlQueryDemo</servlet-class>
		<init-param>
			<description>
			Name of query file held in /WEB-INF</description>
			<param-name>xslFile</param-name>
			<param-value>query.xsl</param-value>
		</init-param>
		<init-param>
			<description>
			Default field used in standard Lucene QueryParser used in UserQuery tag</description>
			<param-name>defaultStandardQueryParserField</param-name>
			<param-value>jobDescription</param-value>
		</init-param>
	</servlet>
	<servlet-mapping>
		<servlet-name>FormBasedXmlQueryDemo</servlet-name>
		<url-pattern>/FormBasedXmlQueryDemo</url-pattern>
	</servlet-mapping>
	<welcome-file-list>
		<welcome-file>index.jsp</welcome-file>
	</welcome-file-list>
</web-app>

整个工程结构如下图:


6. Export出war文件,然后将文件放到tomcat的webapp目录下

7. 在浏览器中输入http://localhost:8080/lucene/,然后搜索lucene,页面如下:


发布了410 篇原创文章 · 获赞 19 · 访问量 76万+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章