├── .classpath
├── .gitignore
├── .mymetadata
├── .project
├── .settings
├── .jsdtscope
├── com.genuitec.eclipse.j2eedt.core.prefs
├── org.eclipse.jdt.core.prefs
├── org.eclipse.wst.common.component
├── org.eclipse.wst.common.project.facet.core.xml
├── org.eclipse.wst.jsdt.ui.superType.container
└── org.eclipse.wst.jsdt.ui.superType.name
├── WebRoot
├── META-INF
│ └── MANIFEST.MF
├── WEB-INF
│ ├── classes
│ │ ├── applicationContext.xml
│ │ ├── com
│ │ │ ├── luo
│ │ │ │ ├── action
│ │ │ │ │ ├── Base2Action.class
│ │ │ │ │ ├── BaseAction.class
│ │ │ │ │ ├── LuceneAction.class
│ │ │ │ │ ├── MessageAction.class
│ │ │ │ │ └── SolrAction.class
│ │ │ │ ├── dao
│ │ │ │ │ ├── BaseDao.class
│ │ │ │ │ ├── MessageDao.class
│ │ │ │ │ └── TempIndexDao.class
│ │ │ │ ├── job
│ │ │ │ │ └── LuceneSyncJob.class
│ │ │ │ ├── pojo
│ │ │ │ │ ├── Message.class
│ │ │ │ │ └── TempIndex.class
│ │ │ │ ├── service
│ │ │ │ │ ├── LuceneService.class
│ │ │ │ │ ├── MessageService.class
│ │ │ │ │ └── SolrService.class
│ │ │ │ ├── test
│ │ │ │ │ ├── Message.class
│ │ │ │ │ └── SolrTest.class
│ │ │ │ ├── util
│ │ │ │ │ ├── IndexUtil.class
│ │ │ │ │ ├── LuceneContext$1.class
│ │ │ │ │ ├── LuceneContext.class
│ │ │ │ │ ├── PropertiesUtil.class
│ │ │ │ │ ├── ReflectUtil.class
│ │ │ │ │ └── SolrContext.class
│ │ │ │ └── vo
│ │ │ │ │ ├── IndexField.class
│ │ │ │ │ └── IndexModel.class
│ │ │ └── taiping
│ │ │ │ └── b2b2e
│ │ │ │ └── common
│ │ │ │ └── page
│ │ │ │ └── PageBean.class
│ │ ├── data
│ │ │ ├── chars.dic
│ │ │ ├── units.dic
│ │ │ ├── words-my.dic
│ │ │ └── words.dic
│ │ ├── ehcache.xml
│ │ └── project.properties
│ ├── content
│ │ ├── addMessage.jsp
│ │ ├── include
│ │ │ └── base.jsp
│ │ ├── luceneList.jsp
│ │ └── messageList.jsp
│ └── web.xml
└── index.jsp
├── etc
├── applicationContext.xml
├── data
│ ├── chars.dic
│ ├── units.dic
│ ├── words-my.dic
│ └── words.dic
├── ehcache.xml
└── project.properties
└── src
└── com
├── luo
├── action
│ ├── Base2Action.java
│ ├── BaseAction.java
│ ├── LuceneAction.java
│ ├── MessageAction.java
│ └── SolrAction.java
├── dao
│ ├── BaseDao.java
│ ├── MessageDao.java
│ └── TempIndexDao.java
├── job
│ └── LuceneSyncJob.java
├── pojo
│ ├── Message.java
│ └── TempIndex.java
├── service
│ ├── LuceneService.java
│ ├── MessageService.java
│ └── SolrService.java
├── test
│ ├── Message.java
│ └── SolrTest.java
├── util
│ ├── IndexUtil.java
│ ├── LuceneContext.java
│ ├── PropertiesUtil.java
│ ├── ReflectUtil.java
│ └── SolrContext.java
└── vo
│ ├── IndexField.java
│ └── IndexModel.java
└── taiping
└── b2b2e
└── common
└── page
└── PageBean.java
/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | /WebRoot/WEB-INF/lib
2 |
--------------------------------------------------------------------------------
/.mymetadata:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | ssh-annotation
4 |
5 |
6 |
7 |
8 |
9 | org.eclipse.wst.common.project.facet.core.builder
10 |
11 |
12 |
13 |
14 | org.eclipse.wst.jsdt.core.javascriptValidator
15 |
16 |
17 |
18 |
19 | com.genuitec.eclipse.j2eedt.core.WebClasspathBuilder
20 |
21 |
22 |
23 |
24 | org.eclipse.jdt.core.javabuilder
25 |
26 |
27 |
28 |
29 | com.genuitec.eclipse.j2eedt.core.J2EEProjectValidator
30 |
31 |
32 |
33 |
34 | com.genuitec.eclipse.j2eedt.core.DeploymentDescriptorValidator
35 |
36 |
37 |
38 |
39 | org.eclipse.wst.validation.validationbuilder
40 |
41 |
42 |
43 |
44 | com.genuitec.eclipse.ast.deploy.core.DeploymentBuilder
45 |
46 |
47 |
48 |
49 |
50 | org.eclipse.jem.workbench.JavaEMFNature
51 | com.genuitec.eclipse.ast.deploy.core.deploymentnature
52 | com.genuitec.eclipse.j2eedt.core.webnature
53 | org.eclipse.jdt.core.javanature
54 | org.eclipse.wst.jsdt.core.jsNature
55 | org.eclipse.wst.common.project.facet.core.nature
56 | org.eclipse.wst.common.modulecore.ModuleCoreNature
57 |
58 |
59 |
--------------------------------------------------------------------------------
/.settings/.jsdtscope:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.settings/com.genuitec.eclipse.j2eedt.core.prefs:
--------------------------------------------------------------------------------
1 | #Wed Jul 31 12:45:30 CST 2013
2 | defaultTldInfo=f\=http\://java.sun.com/jsf/core;http\://java.sun.com/jsf/html\=h;http\://struts.apache.org/tags-bean\=bean;http\://java.sun.com/jsp/jstl/fmt\=fmt;nested\=http\://struts.apache.org/tags-nested;bean\=http\://struts.apache.org/tags-bean;http\://java.sun.com/jsp/jstl/sql\=sql;c\=http\://java.sun.com/jsp/jstl/core;fmt\=http\://java.sun.com/jsp/jstl/fmt;http\://struts.apache.org/tags-logic\=logic;http\://java.sun.com/jsp/jstl/xml\=x;http\://java.sun.com/jsp/jstl/core\=c;logic\=http\://struts.apache.org/tags-logic;h\=http\://java.sun.com/jsf/html;http\://struts.apache.org/tags-tiles\=tiles;http\://java.sun.com/jsp/jstl/functions\=fn;tiles\=http\://struts.apache.org/tags-tiles;sql\=http\://java.sun.com/jsp/jstl/sql;http\://struts.apache.org/tags-html\=html;http\://struts.apache.org/tags-nested\=nested;html\=http\://struts.apache.org/tags-html;http\://java.sun.com/jsf/core\=f;fn\=http\://java.sun.com/jsp/jstl/functions;x\=http\://java.sun.com/jsp/jstl/xml
3 | eclipse.preferences.version=1
4 |
--------------------------------------------------------------------------------
/.settings/org.eclipse.jdt.core.prefs:
--------------------------------------------------------------------------------
1 | #Wed Jul 31 12:45:50 CST 2013
2 | eclipse.preferences.version=1
3 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
4 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
5 | org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
6 | org.eclipse.jdt.core.compiler.compliance=1.6
7 | org.eclipse.jdt.core.compiler.debug.lineNumber=generate
8 | org.eclipse.jdt.core.compiler.debug.localVariable=generate
9 | org.eclipse.jdt.core.compiler.debug.sourceFile=generate
10 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
11 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
12 | org.eclipse.jdt.core.compiler.source=1.6
13 |
--------------------------------------------------------------------------------
/.settings/org.eclipse.wst.common.component:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/.settings/org.eclipse.wst.common.project.facet.core.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/.settings/org.eclipse.wst.jsdt.ui.superType.container:
--------------------------------------------------------------------------------
1 | org.eclipse.wst.jsdt.launching.baseBrowserLibrary
--------------------------------------------------------------------------------
/.settings/org.eclipse.wst.jsdt.ui.superType.name:
--------------------------------------------------------------------------------
1 | Window
--------------------------------------------------------------------------------
/WebRoot/META-INF/MANIFEST.MF:
--------------------------------------------------------------------------------
1 | Manifest-Version: 1.0
2 | Class-Path:
3 |
4 |
--------------------------------------------------------------------------------
/WebRoot/WEB-INF/classes/applicationContext.xml:
--------------------------------------------------------------------------------
1 |
2 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 | root
32 |
33 | 20
34 | 5
35 |
36 |
37 |
38 |
39 |
41 |
42 |
43 |
44 |
45 | true
46 |
47 | org.hibernate.dialect.MySQLDialect
48 |
49 |
50 | org.hibernate.cache.EhCacheProvider
51 |
52 |
53 | ehcache.xml
54 |
55 |
56 |
57 |
58 |
59 |
64 |
65 |
--------------------------------------------------------------------------------
/WebRoot/WEB-INF/classes/com/luo/action/Base2Action.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/doushini/lucene/21878d96a85b7f8d181bef2adecc73dfb8e81147/WebRoot/WEB-INF/classes/com/luo/action/Base2Action.class
--------------------------------------------------------------------------------
/WebRoot/WEB-INF/classes/com/luo/action/BaseAction.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/doushini/lucene/21878d96a85b7f8d181bef2adecc73dfb8e81147/WebRoot/WEB-INF/classes/com/luo/action/BaseAction.class
--------------------------------------------------------------------------------
/WebRoot/WEB-INF/classes/com/luo/action/LuceneAction.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/doushini/lucene/21878d96a85b7f8d181bef2adecc73dfb8e81147/WebRoot/WEB-INF/classes/com/luo/action/LuceneAction.class
--------------------------------------------------------------------------------
/WebRoot/WEB-INF/classes/com/luo/action/MessageAction.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/doushini/lucene/21878d96a85b7f8d181bef2adecc73dfb8e81147/WebRoot/WEB-INF/classes/com/luo/action/MessageAction.class
--------------------------------------------------------------------------------
/WebRoot/WEB-INF/classes/com/luo/action/SolrAction.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/doushini/lucene/21878d96a85b7f8d181bef2adecc73dfb8e81147/WebRoot/WEB-INF/classes/com/luo/action/SolrAction.class
--------------------------------------------------------------------------------
/WebRoot/WEB-INF/classes/com/luo/dao/BaseDao.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/doushini/lucene/21878d96a85b7f8d181bef2adecc73dfb8e81147/WebRoot/WEB-INF/classes/com/luo/dao/BaseDao.class
--------------------------------------------------------------------------------
/WebRoot/WEB-INF/classes/com/luo/dao/MessageDao.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/doushini/lucene/21878d96a85b7f8d181bef2adecc73dfb8e81147/WebRoot/WEB-INF/classes/com/luo/dao/MessageDao.class
--------------------------------------------------------------------------------
/WebRoot/WEB-INF/classes/com/luo/dao/TempIndexDao.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/doushini/lucene/21878d96a85b7f8d181bef2adecc73dfb8e81147/WebRoot/WEB-INF/classes/com/luo/dao/TempIndexDao.class
--------------------------------------------------------------------------------
/WebRoot/WEB-INF/classes/com/luo/job/LuceneSyncJob.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/doushini/lucene/21878d96a85b7f8d181bef2adecc73dfb8e81147/WebRoot/WEB-INF/classes/com/luo/job/LuceneSyncJob.class
--------------------------------------------------------------------------------
/WebRoot/WEB-INF/classes/com/luo/pojo/Message.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/doushini/lucene/21878d96a85b7f8d181bef2adecc73dfb8e81147/WebRoot/WEB-INF/classes/com/luo/pojo/Message.class
--------------------------------------------------------------------------------
/WebRoot/WEB-INF/classes/com/luo/pojo/TempIndex.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/doushini/lucene/21878d96a85b7f8d181bef2adecc73dfb8e81147/WebRoot/WEB-INF/classes/com/luo/pojo/TempIndex.class
--------------------------------------------------------------------------------
/WebRoot/WEB-INF/classes/com/luo/service/LuceneService.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/doushini/lucene/21878d96a85b7f8d181bef2adecc73dfb8e81147/WebRoot/WEB-INF/classes/com/luo/service/LuceneService.class
--------------------------------------------------------------------------------
/WebRoot/WEB-INF/classes/com/luo/service/MessageService.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/doushini/lucene/21878d96a85b7f8d181bef2adecc73dfb8e81147/WebRoot/WEB-INF/classes/com/luo/service/MessageService.class
--------------------------------------------------------------------------------
/WebRoot/WEB-INF/classes/com/luo/service/SolrService.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/doushini/lucene/21878d96a85b7f8d181bef2adecc73dfb8e81147/WebRoot/WEB-INF/classes/com/luo/service/SolrService.class
--------------------------------------------------------------------------------
/WebRoot/WEB-INF/classes/com/luo/test/Message.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/doushini/lucene/21878d96a85b7f8d181bef2adecc73dfb8e81147/WebRoot/WEB-INF/classes/com/luo/test/Message.class
--------------------------------------------------------------------------------
/WebRoot/WEB-INF/classes/com/luo/test/SolrTest.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/doushini/lucene/21878d96a85b7f8d181bef2adecc73dfb8e81147/WebRoot/WEB-INF/classes/com/luo/test/SolrTest.class
--------------------------------------------------------------------------------
/WebRoot/WEB-INF/classes/com/luo/util/IndexUtil.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/doushini/lucene/21878d96a85b7f8d181bef2adecc73dfb8e81147/WebRoot/WEB-INF/classes/com/luo/util/IndexUtil.class
--------------------------------------------------------------------------------
/WebRoot/WEB-INF/classes/com/luo/util/LuceneContext$1.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/doushini/lucene/21878d96a85b7f8d181bef2adecc73dfb8e81147/WebRoot/WEB-INF/classes/com/luo/util/LuceneContext$1.class
--------------------------------------------------------------------------------
/WebRoot/WEB-INF/classes/com/luo/util/LuceneContext.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/doushini/lucene/21878d96a85b7f8d181bef2adecc73dfb8e81147/WebRoot/WEB-INF/classes/com/luo/util/LuceneContext.class
--------------------------------------------------------------------------------
/WebRoot/WEB-INF/classes/com/luo/util/PropertiesUtil.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/doushini/lucene/21878d96a85b7f8d181bef2adecc73dfb8e81147/WebRoot/WEB-INF/classes/com/luo/util/PropertiesUtil.class
--------------------------------------------------------------------------------
/WebRoot/WEB-INF/classes/com/luo/util/ReflectUtil.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/doushini/lucene/21878d96a85b7f8d181bef2adecc73dfb8e81147/WebRoot/WEB-INF/classes/com/luo/util/ReflectUtil.class
--------------------------------------------------------------------------------
/WebRoot/WEB-INF/classes/com/luo/util/SolrContext.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/doushini/lucene/21878d96a85b7f8d181bef2adecc73dfb8e81147/WebRoot/WEB-INF/classes/com/luo/util/SolrContext.class
--------------------------------------------------------------------------------
/WebRoot/WEB-INF/classes/com/luo/vo/IndexField.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/doushini/lucene/21878d96a85b7f8d181bef2adecc73dfb8e81147/WebRoot/WEB-INF/classes/com/luo/vo/IndexField.class
--------------------------------------------------------------------------------
/WebRoot/WEB-INF/classes/com/luo/vo/IndexModel.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/doushini/lucene/21878d96a85b7f8d181bef2adecc73dfb8e81147/WebRoot/WEB-INF/classes/com/luo/vo/IndexModel.class
--------------------------------------------------------------------------------
/WebRoot/WEB-INF/classes/com/taiping/b2b2e/common/page/PageBean.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/doushini/lucene/21878d96a85b7f8d181bef2adecc73dfb8e81147/WebRoot/WEB-INF/classes/com/taiping/b2b2e/common/page/PageBean.class
--------------------------------------------------------------------------------
/WebRoot/WEB-INF/classes/data/units.dic:
--------------------------------------------------------------------------------
1 | #说明:单个字的单位, 与数字一起出现的(前面是数字). 如:2009年
2 | #注意:如果"分"加入到些文件中,"20分钟"就被分成"20|分|钟". 如果你想分成"20|分钟",那就把"分"注释掉.
3 | # 作者认为:像"分"和"分钟"都是单位的话,不把"分"加入.
4 | #时间
5 | 年
6 | 月
7 | 日
8 | 时
9 | #单位"分钟"已经是词,就不把"分"加入了
10 | #分
11 | 秒
12 | #币
13 | 元
14 | 角
15 | #长度
16 | 米
17 | 寸
18 | 尺
19 | 丈
20 | 里
21 | #容量
22 | 升
23 | 斗
24 | 石
25 | #重量
26 | 吨
27 | 克
28 | 斤
29 | 两
30 | 担
31 | #地积
32 | 亩
33 | 顷
--------------------------------------------------------------------------------
/WebRoot/WEB-INF/classes/data/words-my.dic:
--------------------------------------------------------------------------------
1 | 白云山
2 | 昭通
3 | 昭阳区
--------------------------------------------------------------------------------
/WebRoot/WEB-INF/classes/ehcache.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
15 |
16 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/WebRoot/WEB-INF/classes/project.properties:
--------------------------------------------------------------------------------
1 | luceneIndex=G:/lucene/solr/home/data/index
2 | uploadDir=G:/lucene/solr/upload/
3 |
--------------------------------------------------------------------------------
/WebRoot/WEB-INF/content/addMessage.jsp:
--------------------------------------------------------------------------------
1 | <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
2 |
3 |
4 |
5 |
6 | My JSP 'createuser-success.jsp' starting page
7 |
8 |
9 |
10 |
11 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/WebRoot/WEB-INF/content/include/base.jsp:
--------------------------------------------------------------------------------
1 | <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
2 | <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
3 |
4 |
--------------------------------------------------------------------------------
/WebRoot/WEB-INF/content/luceneList.jsp:
--------------------------------------------------------------------------------
1 | <%@ page language="java" pageEncoding="UTF-8"%>
2 | <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
3 |
4 |
5 |
6 |
7 | My JSP 'user-success.jsp' starting page
8 |
14 |
15 |
16 |
17 | 提交内存中的索引
18 | 提交数据库中的索引
19 | 重构所有索引
20 | 删除所有索引
21 |
22 |
23 | ID |
24 | 标题 |
25 | 简介 |
26 |
27 |
28 |
29 | ${m.id} |
30 | ${m.title} |
31 | ${m.summary} |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
--------------------------------------------------------------------------------
/WebRoot/WEB-INF/content/messageList.jsp:
--------------------------------------------------------------------------------
1 | <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
2 | <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
3 |
4 |
5 |
6 |
7 | My JSP 'user-success.jsp' starting page
8 |
9 |
10 |
11 |
12 | 添加新留言
13 |
14 |
23 |
24 |
25 | ID |
26 | 标题 |
27 | 添加时间 |
28 |
29 |
30 |
31 | ${m.id} |
32 | ${m.title} |
33 | ${m.addTime} |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
--------------------------------------------------------------------------------
/WebRoot/WEB-INF/web.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 | index.jsp
9 |
10 |
11 |
12 |
13 |
14 | org.springframework.web.context.ContextLoaderListener
15 |
16 |
17 |
18 | contextConfigLocation
19 |
20 | classpath:applicationContext*.xml
21 |
22 |
23 |
24 |
25 |
26 | openSessionInView
27 | org.springframework.orm.hibernate3.support.OpenSessionInViewFilter
28 |
29 |
30 | openSessionInView
31 | /*
32 |
33 |
34 |
35 |
36 |
37 | struts2
38 | org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
39 |
40 |
41 | struts2
42 | /*
43 |
44 |
45 |
46 |
47 |
48 |
--------------------------------------------------------------------------------
/WebRoot/index.jsp:
--------------------------------------------------------------------------------
1 | <%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
2 | <%
3 | response.sendRedirect("message/list.action");
4 | %>
5 |
--------------------------------------------------------------------------------
/etc/applicationContext.xml:
--------------------------------------------------------------------------------
1 |
2 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 | root
32 |
33 | 20
34 | 5
35 |
36 |
37 |
38 |
39 |
41 |
42 |
43 |
44 |
45 | true
46 |
47 | org.hibernate.dialect.MySQLDialect
48 |
49 |
50 | org.hibernate.cache.EhCacheProvider
51 |
52 |
53 | ehcache.xml
54 |
55 |
56 |
57 |
58 |
59 |
64 |
65 |
--------------------------------------------------------------------------------
/etc/data/units.dic:
--------------------------------------------------------------------------------
1 | #说明:单个字的单位, 与数字一起出现的(前面是数字). 如:2009年
2 | #注意:如果"分"加入到些文件中,"20分钟"就被分成"20|分|钟". 如果你想分成"20|分钟",那就把"分"注释掉.
3 | # 作者认为:像"分"和"分钟"都是单位的话,不把"分"加入.
4 | #时间
5 | 年
6 | 月
7 | 日
8 | 时
9 | #单位"分钟"已经是词,就不把"分"加入了
10 | #分
11 | 秒
12 | #币
13 | 元
14 | 角
15 | #长度
16 | 米
17 | 寸
18 | 尺
19 | 丈
20 | 里
21 | #容量
22 | 升
23 | 斗
24 | 石
25 | #重量
26 | 吨
27 | 克
28 | 斤
29 | 两
30 | 担
31 | #地积
32 | 亩
33 | 顷
--------------------------------------------------------------------------------
/etc/data/words-my.dic:
--------------------------------------------------------------------------------
1 | 白云山
2 | 昭通
3 | 昭阳区
--------------------------------------------------------------------------------
/etc/ehcache.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
15 |
16 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/etc/project.properties:
--------------------------------------------------------------------------------
1 | luceneIndex=G:/lucene/solr/home/data/index
2 | uploadDir=G:/lucene/solr/upload/
3 |
--------------------------------------------------------------------------------
/src/com/luo/action/Base2Action.java:
--------------------------------------------------------------------------------
1 | package com.luo.action;
2 |
3 | import java.util.Map;
4 | import javax.servlet.http.HttpServletRequest;
5 | import javax.servlet.http.HttpServletResponse;
6 | import org.apache.struts2.ServletActionContext;
7 | import com.opensymphony.xwork2.ActionContext;
8 | import com.opensymphony.xwork2.ActionSupport;
9 |
10 | public class Base2Action extends ActionSupport{
11 |
12 | private static final long serialVersionUID = 1L;
13 | public ActionContext actionContext=ActionContext.getContext();
14 | public HttpServletRequest request=(HttpServletRequest) actionContext.get(ServletActionContext.HTTP_REQUEST);
15 | public HttpServletResponse response=(HttpServletResponse) actionContext.get(ServletActionContext.HTTP_RESPONSE);
16 | public Map session=actionContext.getSession();//使用SessionMap即可做所有操作,无需使用HttpServletSession
17 | public Map application=actionContext.getApplication();
18 |
19 | }
20 |
--------------------------------------------------------------------------------
/src/com/luo/action/BaseAction.java:
--------------------------------------------------------------------------------
1 | package com.luo.action;
2 | import java.util.Map;
3 | import javax.servlet.ServletContext;
4 | import javax.servlet.http.HttpServletRequest;
5 | import javax.servlet.http.HttpServletResponse;
6 | import org.apache.struts2.interceptor.ServletRequestAware;
7 | import org.apache.struts2.interceptor.ServletResponseAware;
8 | import org.apache.struts2.interceptor.SessionAware;
9 | import org.springframework.context.annotation.Scope;
10 | import com.opensymphony.xwork2.ActionSupport;
11 |
12 |
13 | @Scope("prototype")
14 | public abstract class BaseAction extends ActionSupport implements ServletRequestAware,ServletResponseAware,SessionAware{
15 |
16 | private static final long serialVersionUID = 1L;
17 | public static final String LIST = "list";
18 | public HttpServletRequest request;
19 | public HttpServletResponse response;
20 | public Map session;
21 | public ServletContext application;
22 |
23 |
24 | @Override
25 | public void setServletRequest(HttpServletRequest request) {
26 | this.request = request;
27 | this.application=request.getSession().getServletContext();
28 | }
29 | @Override
30 | public void setSession(Map session) {
31 | this.session=session;
32 | }
33 | @Override
34 | public void setServletResponse(HttpServletResponse response) {
35 | this.response=response;
36 | }
37 |
38 |
39 |
40 | @Override
41 | public String execute() throws Exception {
42 | return list();
43 | }
44 | public abstract String list() throws Exception;
45 | }
46 |
--------------------------------------------------------------------------------
/src/com/luo/action/LuceneAction.java:
--------------------------------------------------------------------------------
1 | package com.luo.action;
2 |
3 | import java.util.List;
4 |
5 | import org.apache.struts2.convention.annotation.Action;
6 | import org.apache.struts2.convention.annotation.Namespace;
7 | import org.apache.struts2.convention.annotation.Result;
8 | import org.springframework.beans.factory.annotation.Autowired;
9 | import org.springframework.context.annotation.Scope;
10 |
11 | import com.luo.service.LuceneService;
12 | import com.luo.vo.IndexModel;
13 | import com.opensymphony.xwork2.ActionContext;
14 |
15 |
16 | @Scope("prototype")
17 | @Namespace("/lucene")
18 | @Result(name="list",type="redirectAction",location="search.action")
19 | public class LuceneAction extends BaseAction{
20 |
21 | private static final long serialVersionUID = 1L;
22 | private String keyword;
23 | private String field;
24 | @Autowired
25 | private LuceneService luceneService;
26 |
27 |
28 | @Action(value="search",results={@Result(name=SUCCESS,location="/WEB-INF/content/luceneList.jsp")})
29 | @Override
30 | public String list() throws Exception {
31 | List luceneList=luceneService.search(keyword);
32 | ActionContext.getContext().put("luceneList", luceneList);
33 | return SUCCESS;
34 | }
35 |
36 | @Action(value="commitRamIndex")
37 | public String commitRamIndex() throws Exception {
38 | luceneService.commitRamIndex();
39 | return LIST;
40 | }
41 |
42 | @Action(value="commitDBIndex")
43 | public String commitDBIndex() throws Exception {
44 | luceneService.commitDBIndex();
45 | return LIST;
46 | }
47 |
48 | @Action(value="reCreCommitIndex")
49 | public String reCreCommitIndex() throws Exception {
50 | luceneService.updateReconstructorIndex();
51 | return LIST;
52 | }
53 |
54 | @Action(value="deleteIndex")
55 | public String deleteIndex() throws Exception {
56 | luceneService.deleteIndex();
57 | return LIST;
58 | }
59 | public String getKeyword() {
60 | return keyword;
61 | }
62 | public void setKeyword(String keyword) {
63 | this.keyword = keyword;
64 | }
65 |
66 | public String getField() {
67 | return field;
68 | }
69 |
70 | public void setField(String field) {
71 | this.field = field;
72 | }
73 | }
74 |
--------------------------------------------------------------------------------
/src/com/luo/action/MessageAction.java:
--------------------------------------------------------------------------------
1 | package com.luo.action;
2 |
3 | import java.io.File;
4 | import java.util.Date;
5 | import java.util.List;
6 |
7 | import javax.servlet.ServletContext;
8 |
9 | import org.apache.commons.io.FileUtils;
10 | import org.apache.struts2.convention.annotation.Action;
11 | import org.apache.struts2.convention.annotation.Namespace;
12 | import org.apache.struts2.convention.annotation.Result;
13 | import org.springframework.beans.factory.annotation.Autowired;
14 | import org.springframework.context.annotation.Scope;
15 |
16 | import com.luo.pojo.Message;
17 | import com.luo.service.MessageService;
18 | import com.luo.util.PropertiesUtil;
19 |
20 | @Scope(value="prototype")
21 | @Namespace("/message")
22 | @Result(name="list",type="redirectAction",location="/list.action")
23 | public class MessageAction extends BaseAction{
24 |
25 | private static final long serialVersionUID = 1L;
26 | @Autowired
27 | private MessageService messageService;
28 | private Message message;
29 | private List messageList;
30 | private File file;
31 | private String fileFileName;
32 |
33 |
34 | public Message getMessage() {
35 | return message;
36 | }
37 |
38 | public void setMessage(Message message) {
39 | this.message = message;
40 | }
41 |
42 | public List getMessageList() {
43 | return messageList;
44 | }
45 |
46 | public void setMessageList(List messageList) {
47 | this.messageList = messageList;
48 | }
49 |
50 | @Action(value="list",results={@Result(name=SUCCESS,location="/WEB-INF/content/messageList.jsp")})
51 | @Override
52 | public String list() throws Exception {
53 | messageList = messageService.list();
54 | return SUCCESS;
55 | }
56 |
57 | @Action(value="addMessage",results={@Result(name=SUCCESS,location="/WEB-INF/content/addMessage.jsp")})
58 | public String add() throws Exception {
59 | return SUCCESS;
60 | }
61 |
62 | @Action(value="saveMessage")
63 | public String save() throws Exception {
64 | message.setAddTime(new Date());
65 | String path = request.getRealPath("/upload");
66 | String fName=new Date().getTime()+fileFileName;
67 | if(file!=null){
68 | File f=new File(path,fName);
69 | FileUtils.copyFile(file, f);//不是
70 | message.setAttachUrl(f.getPath());
71 | }
72 | messageService.save(message);
73 | return LIST;
74 | }
75 |
76 | public String del() throws Exception {
77 | messageService.delete(message.getId());
78 | return LIST;
79 | }
80 |
81 | public String getFileFileName() {
82 | return fileFileName;
83 | }
84 |
85 | public void setFileFileName(String fileFileName) {
86 | this.fileFileName = fileFileName;
87 | }
88 |
89 | public File getFile() {
90 | return file;
91 | }
92 |
93 | public void setFile(File file) {
94 | this.file = file;
95 | }
96 | }
97 |
--------------------------------------------------------------------------------
/src/com/luo/action/SolrAction.java:
--------------------------------------------------------------------------------
1 | package com.luo.action;
2 |
3 | import org.apache.struts2.convention.annotation.Action;
4 | import org.apache.struts2.convention.annotation.Result;
5 | import org.springframework.beans.factory.annotation.Autowired;
6 | import org.springframework.context.annotation.Scope;
7 | import com.luo.service.SolrService;
8 | import com.luo.vo.IndexModel;
9 | import com.taiping.b2b2e.common.page.PageBean;
10 |
11 | @Scope("prototype")
12 | @Result(name="list",type="redirectAction",location="search.action")
13 | public class SolrAction extends BaseAction {
14 |
15 | private static final long serialVersionUID = 1L;
16 | private String keyword;
17 | private String field;
18 | @Autowired
19 | private SolrService solrService;
20 | private PageBean page;
21 | private final Integer pageSize=5;
22 | private int pageIndex;
23 |
24 |
25 | /**
26 | * 从索引中检索关键词
27 | */
28 | @Action(value="search",results={@Result(name=SUCCESS,location="/WEB-INF/content/luceneList.jsp")})
29 | @Override
30 | public String list() throws Exception {
31 | page = solrService.findByIndex(keyword,field,pageIndex,pageSize);
32 | return SUCCESS;
33 | }
34 |
35 |
36 | @Action(value="commitRamIndex")
37 | public String commitRamIndex() throws Exception {
38 | solrService.commitRamIndex();
39 | return LIST;
40 | }
41 |
42 | @Action(value="commitDBIndex")
43 | public String commitDBIndex() throws Exception {
44 | solrService.commitDBIndex();
45 | return LIST;
46 | }
47 |
48 | @Action(value="reCreCommitIndex")
49 | public String reCreCommitIndex() throws Exception {
50 | solrService.updateReconstructorIndex();
51 | return LIST;
52 | }
53 |
54 | @Action(value="deleteIndex")
55 | public String deleteIndex() throws Exception {
56 | solrService.deleteIndex();
57 | return LIST;
58 | }
59 |
60 | //get set
61 | public String getKeyword() {
62 | return keyword;
63 | }
64 | public void setKeyword(String keyword) {
65 | this.keyword = keyword;
66 | }
67 | public String getField() {
68 | return field;
69 | }
70 | public void setField(String field) {
71 | this.field = field;
72 | }
73 | public int getPageIndex() {
74 | return pageIndex;
75 | }
76 | public void setPageIndex(int pageIndex) {
77 | this.pageIndex = pageIndex;
78 | }
79 | public PageBean getPage() {
80 | return page;
81 | }
82 | public void setPage(PageBean page) {
83 | this.page = page;
84 | }
85 | }
86 |
--------------------------------------------------------------------------------
/src/com/luo/dao/BaseDao.java:
--------------------------------------------------------------------------------
1 | package com.luo.dao;
2 |
3 | import java.io.Serializable;
4 | import java.util.List;
5 |
6 | import org.hibernate.Criteria;
7 | import org.hibernate.Session;
8 | import org.hibernate.SessionFactory;
9 | import org.springframework.beans.factory.annotation.Autowired;
10 |
11 | import com.luo.util.ReflectUtil;
12 |
13 |
14 | public class BaseDao {
15 |
16 | private SessionFactory sessionFactory;
17 | private Class> entityClass;
18 |
19 | public BaseDao(){
20 | entityClass = ReflectUtil.getGenericParmeterType(this.getClass());
21 | }
22 |
23 | public void save(T t) {
24 | getSession().saveOrUpdate(t);
25 | }
26 |
27 | @SuppressWarnings("unchecked")
28 | public T findById(PK id) {
29 | return (T) getSession().get(entityClass, id);
30 | }
31 |
32 | public void del(PK id) {
33 | getSession().delete(findById(id));
34 | }
35 |
36 | public void del(T t) {
37 | getSession().delete(t);
38 | }
39 |
40 | @SuppressWarnings("unchecked")
41 | public List findAll() {
42 | Criteria c = getSession().createCriteria(entityClass);
43 | return c.list();
44 | }
45 |
46 | @SuppressWarnings("unchecked")
47 | public List findByPage(int start,int count) {
48 | Criteria c = getSession().createCriteria(entityClass);
49 | c.setFirstResult(start);
50 | c.setMaxResults(count);
51 | return c.list();
52 | }
53 |
54 |
55 |
56 | public Session getSession() {
57 | return sessionFactory.getCurrentSession();
58 | }
59 |
60 | @Autowired
61 | public void setSessionFactory(SessionFactory sessionFactory) {
62 | this.sessionFactory = sessionFactory;
63 | }
64 |
65 |
66 |
67 |
68 | }
69 |
--------------------------------------------------------------------------------
/src/com/luo/dao/MessageDao.java:
--------------------------------------------------------------------------------
1 | package com.luo.dao;
2 |
3 | import org.springframework.stereotype.Component;
4 |
5 | import com.luo.pojo.Message;
6 |
7 | @Component
8 | public class MessageDao extends BaseDao {
9 |
10 | }
11 |
--------------------------------------------------------------------------------
/src/com/luo/dao/TempIndexDao.java:
--------------------------------------------------------------------------------
1 | package com.luo.dao;
2 |
3 | import java.util.List;
4 |
5 | import org.springframework.stereotype.Repository;
6 |
7 | import com.luo.pojo.TempIndex;
8 |
9 | @Repository
10 | public class TempIndexDao extends BaseDao{
11 |
12 | public void deleteAll() {
13 | List tempIndexList=this.findAll();
14 | for (TempIndex tempIndex : tempIndexList) {
15 | this.del(tempIndex);
16 | }
17 | }
18 |
19 | }
20 |
--------------------------------------------------------------------------------
/src/com/luo/job/LuceneSyncJob.java:
--------------------------------------------------------------------------------
1 | package com.luo.job;
2 |
3 | import org.springframework.beans.factory.annotation.Autowired;
4 |
5 | import com.luo.service.LuceneService;
6 |
7 | public class LuceneSyncJob {
8 | @Autowired
9 | private LuceneService luceneService;
10 |
11 |
12 | public void execute(){
13 | luceneService.createIndex();
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/src/com/luo/pojo/Message.java:
--------------------------------------------------------------------------------
1 | package com.luo.pojo;
2 |
3 | import java.util.Date;
4 |
5 | import javax.persistence.Column;
6 | import javax.persistence.Entity;
7 | import javax.persistence.GeneratedValue;
8 | import javax.persistence.GenerationType;
9 | import javax.persistence.Id;
10 | import javax.persistence.Table;
11 |
12 | import org.hibernate.annotations.Cache;
13 | import org.hibernate.annotations.CacheConcurrencyStrategy;
14 |
15 |
16 | @Entity
17 | @Table(name="t_message")
18 | @Cache(usage=CacheConcurrencyStrategy.READ_WRITE)
19 | public class Message {
20 | private int id;
21 | private String title;
22 | private String content;
23 | private String attachUrl;
24 | private Date addTime;
25 |
26 |
27 | @Id
28 | @GeneratedValue(strategy=GenerationType.IDENTITY)
29 | public int getId() {
30 | return id;
31 | }
32 | public void setId(int id) {
33 | this.id = id;
34 | }
35 | public String getTitle() {
36 | return title;
37 | }
38 | public void setTitle(String title) {
39 | this.title = title;
40 | }
41 | public String getContent() {
42 | return content;
43 | }
44 | public void setContent(String content) {
45 | this.content = content;
46 | }
47 | @Column(name="add_time")
48 | public Date getAddTime() {
49 | return addTime;
50 | }
51 | public void setAddTime(Date addTime) {
52 | this.addTime = addTime;
53 | }
54 | @Column(name="attach_url")
55 | public String getAttachUrl() {
56 | return attachUrl;
57 | }
58 | public void setAttachUrl(String attachUrl) {
59 | this.attachUrl = attachUrl;
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/src/com/luo/pojo/TempIndex.java:
--------------------------------------------------------------------------------
1 | package com.luo.pojo;
2 |
3 | import javax.persistence.Entity;
4 | import javax.persistence.Table;
5 |
6 |
7 | @Entity
8 | @Table(name="t_temp_index")
9 | public class TempIndex {
10 |
11 | private int id;
12 | }
13 |
--------------------------------------------------------------------------------
/src/com/luo/service/LuceneService.java:
--------------------------------------------------------------------------------
1 | package com.luo.service;
2 |
3 | import java.io.File;
4 | import java.util.ArrayList;
5 | import java.util.List;
6 | import org.apache.lucene.search.IndexSearcher;
7 | import org.apache.lucene.store.Directory;
8 | import org.apache.lucene.store.FSDirectory;
9 | import org.springframework.beans.factory.annotation.Autowired;
10 | import org.springframework.stereotype.Service;
11 |
12 | import com.luo.dao.TempIndexDao;
13 | import com.luo.util.LuceneContext;
14 | import com.luo.util.PropertiesUtil;
15 | import com.luo.vo.IndexModel;
16 |
17 | @Service
18 | public class LuceneService {
19 | @Autowired
20 | private TempIndexDao tempIndexDao;
21 |
22 |
23 | public List search(String keyword) {
24 | String indexDir = PropertiesUtil.get("luceneIndex");
25 | List list=new ArrayList();
26 | try {
27 | //1、创建索引目录
28 | Directory directory=FSDirectory.open(new File(indexDir));
29 |
30 | IndexSearcher indexSearcher=new IndexSearcher(directory);
31 | } catch (Exception e) {
32 | e.printStackTrace();
33 | }
34 | return list;
35 | }
36 |
37 | public void createIndex() {
38 | // LuceneContext.getContext()
39 | }
40 |
41 |
42 | public void commitRamIndex() {
43 | tempIndexDao.deleteAll();
44 | LuceneContext.getContext().commitIndex();
45 | }
46 | public void commitDBIndex() {
47 | // TODO Auto-generated method stub
48 |
49 | }
50 | public void updateReconstructorIndex() {
51 | // TODO Auto-generated method stub
52 |
53 | }
54 | public void deleteIndex() {
55 | // TODO Auto-generated method stub
56 |
57 | }
58 |
59 | }
60 |
--------------------------------------------------------------------------------
/src/com/luo/service/MessageService.java:
--------------------------------------------------------------------------------
1 | package com.luo.service;
2 |
3 | import java.util.List;
4 |
5 | import org.springframework.beans.factory.annotation.Autowired;
6 | import org.springframework.stereotype.Service;
7 | import org.springframework.transaction.annotation.Transactional;
8 |
9 | import com.luo.dao.MessageDao;
10 | import com.luo.pojo.Message;
11 | import com.luo.util.IndexUtil;
12 | import com.luo.vo.IndexField;
13 |
14 | @Service
15 | @Transactional
16 | public class MessageService {
17 | @Autowired
18 | private MessageDao messageDao;
19 | @Autowired
20 | private SolrService solrService;
21 |
22 | public List list() {
23 | return messageDao.findAll();
24 | }
25 |
26 | public void save(Message message) {
27 | messageDao.save(message);
28 |
29 | //添加索引
30 | IndexField indexField=IndexUtil.message2IndexField(message);
31 | solrService.addIndex(indexField);
32 | }
33 |
34 | public void delete(int id) {
35 | messageDao.del(id);
36 |
37 | //删除索引
38 | Message message=messageDao.findById(id);
39 | IndexField indexField=IndexUtil.message2IndexField(message);
40 | solrService.deleteIndex(indexField);
41 | }
42 |
43 | }
44 |
--------------------------------------------------------------------------------
/src/com/luo/service/SolrService.java:
--------------------------------------------------------------------------------
1 | package com.luo.service;
2 |
3 | import java.io.IOException;
4 | import java.util.ArrayList;
5 | import java.util.Date;
6 | import java.util.List;
7 | import java.util.Map;
8 |
9 | import org.apache.solr.client.solrj.SolrQuery;
10 | import org.apache.solr.client.solrj.SolrServer;
11 | import org.apache.solr.client.solrj.SolrServerException;
12 | import org.apache.solr.client.solrj.response.QueryResponse;
13 | import org.apache.solr.common.SolrDocument;
14 | import org.apache.solr.common.SolrDocumentList;
15 | import org.springframework.beans.factory.annotation.Autowired;
16 | import org.springframework.stereotype.Service;
17 |
18 | import com.luo.dao.MessageDao;
19 | import com.luo.pojo.Message;
20 | import com.luo.util.IndexUtil;
21 | import com.luo.util.SolrContext;
22 | import com.luo.vo.IndexField;
23 | import com.luo.vo.IndexModel;
24 | import com.taiping.b2b2e.common.page.PageBean;
25 |
26 | @Service
27 | public class SolrService {
28 |
29 | @Autowired
30 | private MessageDao messageDao;
31 |
32 |
33 | public void commitRamIndex(){
34 | try {
35 | SolrContext.getServer().commit();
36 | } catch (SolrServerException e) {
37 | e.printStackTrace();
38 | } catch (IOException e) {
39 | e.printStackTrace();
40 | }
41 | }
42 |
43 |
44 | /**
45 | * 重构所有的索引
46 | * 把数据库中所有的记录查出开,构建IndexField添加到索引中
47 | * Author:罗辉 ,Date:Aug 2, 2013
48 | */
49 | public void updateReconstructorIndex(){
50 | try {
51 | //1、先删除所有的索引
52 | SolrContext.getServer().deleteByQuery("*:*");
53 |
54 | //2、取出所有数据,构建indexField
55 | List messageList=messageDao.findAll();
56 | indexMessageList(messageList);
57 | } catch (Exception e) {
58 | e.printStackTrace();
59 | }
60 | }
61 |
62 | /**
63 | * 为所有的数据构建索引
64 | * Author:罗辉 ,Date:Aug 2, 2013
65 | */
66 | private void indexMessageList(List messageList) {
67 | for (Message message : messageList) {
68 | IndexField indexField=IndexUtil.message2IndexField(message);
69 | addIndex(indexField);
70 | }
71 | }
72 |
73 | /**
74 | * 添加索引
75 | * Author:罗辉 ,Date:Aug 2, 2013
76 | */
77 | public void addIndex(IndexField indexField) {
78 | try {
79 | //1、添加索引到solr
80 | SolrServer solrServer = SolrContext.getServer();
81 | solrServer.addBean(indexField);
82 | //2、优化索引
83 | solrServer.optimize();
84 | //2、提交索引
85 | SolrContext.getServer().commit();
86 | } catch (IOException e) {
87 | e.printStackTrace();
88 | } catch (SolrServerException e) {
89 | e.printStackTrace();
90 | }
91 | }
92 |
93 | /**
94 | * 检索
95 | * Author:罗辉 ,Date:Aug 2, 2013
96 | * @param field
97 | */
98 | public PageBean findByIndex(String keyword, String field,Integer start,int pageSize) throws SolrServerException {
99 | if(keyword==null)keyword="*";
100 | if(field==null)field="*";
101 | SolrQuery solrQuery=new SolrQuery(field+":"+keyword);
102 | solrQuery.addSortField("last_modified", SolrQuery.ORDER.desc);
103 | solrQuery.setHighlight(true)//设置显示高亮
104 | .setHighlightSimplePre("")
105 | .setHighlightSimplePost("")//设置高亮的样式
106 | .setParam("hl.fl", "title,content,description")//设置高亮的域
107 | // .setParam("hl.fl", "title,content,summary")//设置高亮的域
108 | .setStart(start)//设置分页
109 | .setRows(pageSize);
110 |
111 | QueryResponse queryResponse = SolrContext.getServer().query(solrQuery);//solrQuery是SolrParams的子类
112 | //第一个map的key是文档document的ID,第二个map的key'是要高亮显示的field
113 | Map>> map=queryResponse.getHighlighting();
114 | SolrDocumentList solrDocumentList=queryResponse.getResults();
115 | PageBean page = new PageBean(new Long(solrDocumentList.getNumFound()).intValue());
116 | page.setPageSize(pageSize);
117 | page.setStartRow(start);
118 | List datas=new ArrayList();
119 | for (SolrDocument sd : solrDocumentList) {
120 | String id = (String) sd.getFieldValue("id");
121 | String title = (String) sd.getFieldValue("title");
122 | String summary = (String) sd.getFieldValue("description");
123 | List content = (List) sd.getFieldValue("content");//multiValued="true"的field返回List
124 |
125 | IndexModel indexModel=new IndexModel();
126 | indexModel.setTitle(title);
127 | indexModel.setSummary(summary);
128 | // Map> glMap=map.get(id);
129 | // List titleList = glMap.get("title");
130 | // if(titleList!=null&&titleList.size()!=0){
131 | // indexModel.setTitle(titleList.get(0));//获取高亮
132 | // }
133 | // List summaryList = glMap.get("description");
134 | // if(summaryList!=null&&summaryList.size()!=0){
135 | // indexModel.setSummary(summaryList.get(0));//获取高亮
136 | // }
137 | // List content = glMap.get("content");//获取高亮
138 | Date addTime = (Date) sd.getFieldValue("last_modified");
139 | indexModel.setId(id);
140 | indexModel.setContent(content.get(0));
141 | indexModel.setAddTime(addTime);
142 | datas.add(indexModel);
143 | }
144 | page.setResultList(datas);
145 | return page;
146 | }
147 |
148 | /**
149 | * 删除索引
150 | * Author:罗辉 ,Date:Aug 2, 2013
151 | */
152 | public void deleteIndex(IndexField indexField) {
153 | try {
154 | SolrContext.getServer().deleteById(indexField.getId());
155 | SolrContext.getServer().commit();
156 | } catch (SolrServerException e) {
157 | e.printStackTrace();
158 | } catch (IOException e) {
159 | e.printStackTrace();
160 | }
161 | }
162 |
163 |
164 | public void commitDBIndex() {
165 | try {
166 | SolrContext.getServer().commit();
167 | } catch (SolrServerException e) {
168 | e.printStackTrace();
169 | } catch (IOException e) {
170 | e.printStackTrace();
171 | }
172 | }
173 |
174 |
175 | public void deleteIndex() {
176 | try {
177 | SolrContext.getServer().deleteByQuery("*:*");
178 | SolrContext.getServer().commit();
179 | } catch (SolrServerException e) {
180 | e.printStackTrace();
181 | } catch (IOException e) {
182 | e.printStackTrace();
183 | }
184 | }
185 | }
186 |
--------------------------------------------------------------------------------
/src/com/luo/test/Message.java:
--------------------------------------------------------------------------------
1 | package com.luo.test;
2 |
3 | import org.apache.solr.client.solrj.beans.Field;
4 |
5 | public class Message {
6 | private String id;
7 | private String title;
8 | private String[] content;//数组可以添加内容和附件
9 |
10 | public Message() {
11 | super();
12 | }
13 | public Message(String id, String title, String[] content) {
14 | super();
15 | this.id = id;
16 | this.title = title;
17 | this.content = content;
18 | }
19 | public String getId() {
20 | return id;
21 | }
22 | @Field
23 | public void setId(String id) {
24 | this.id = id;
25 | }
26 | public String getTitle() {
27 | return title;
28 | }
29 | @Field("title")//当和schema.xml中的Filed名字不一样,需要写出来
30 | public void setTitle(String title) {
31 | this.title = title;
32 | }
33 | public String[] getContent() {
34 | return content;
35 | }
36 | @Field("")//此处是数组,是多值,相应的content应该设置multiValued="true"
37 | public void setContent(String[] content) {
38 | this.content = content;
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/src/com/luo/test/SolrTest.java:
--------------------------------------------------------------------------------
1 | package com.luo.test;
2 |
3 | import java.net.MalformedURLException;
4 | import java.util.ArrayList;
5 | import java.util.List;
6 |
7 | import org.apache.solr.client.solrj.impl.CommonsHttpSolrServer;
8 | import org.apache.solr.common.SolrInputDocument;
9 | import org.junit.Before;
10 | import org.junit.Test;
11 |
12 | public class SolrTest {
13 | private final static String solrServerUrl="http://localhost:8080/solr";
14 | private CommonsHttpSolrServer server=null;
15 |
16 | @Before
17 | public void init(){
18 | try {
19 | server=new CommonsHttpSolrServer(solrServerUrl);
20 | } catch (MalformedURLException e) {
21 | e.printStackTrace();
22 | }
23 | }
24 |
25 | @Test
26 | public void test0(){
27 | //1、创建solrServer对象CommonsHttpSolrServer
28 | try {
29 | CommonsHttpSolrServer server=new CommonsHttpSolrServer(solrServerUrl);
30 | server.deleteByQuery("*:*");
31 | server.commit();
32 | } catch (Exception e) {
33 | e.printStackTrace();
34 | }
35 | }
36 | @Test
37 | public void test1(){
38 | //1、创建solrServer对象CommonsHttpSolrServer
39 | try {
40 | SolrInputDocument doc=new SolrInputDocument();
41 | doc.addField("id", "1");//id是唯一的主键,当相同的id添加后面的覆盖前面的
42 | doc.addField("title", "这是我第一个solrj程序,累");//最好在schema.xml将tile改为自己的field,如msg_title
43 | doc.addField("description", "我不爱学习爱睡觉");
44 | server.add(doc);
45 | server.commit();
46 | } catch (Exception e) {
47 | e.printStackTrace();
48 | }
49 | }
50 |
51 |
52 | /**
53 | * 基于java bean的添加
54 | * Author:罗辉 ,Date:2013-7-31
55 | */
56 | @Test
57 | public void test2(){
58 | //1、创建solrServer对象CommonsHttpSolrServer
59 | try {
60 | List messages=new ArrayList();
61 | Message m1=new Message("2","基于java bean的添加", new String[]{"java bean内容","java bean添加的附件"});
62 | messages.add(m1);
63 | Message m2=new Message("3","基于java bean的数据添加", new String[]{"数据添加,没有附件"});
64 | messages.add(m2);
65 | server.addBeans(messages);
66 | server.commit();
67 | } catch (Exception e) {
68 | e.printStackTrace();
69 | }
70 | }
71 |
72 |
73 | }
74 |
--------------------------------------------------------------------------------
/src/com/luo/util/IndexUtil.java:
--------------------------------------------------------------------------------
1 | package com.luo.util;
2 |
3 | import java.io.File;
4 | import java.io.IOException;
5 |
6 | import org.apache.tika.Tika;
7 | import org.apache.tika.exception.TikaException;
8 |
9 | import com.luo.pojo.Message;
10 | import com.luo.vo.IndexField;
11 |
12 | public class IndexUtil {
13 |
14 | public static IndexField message2IndexField(Message message) {
15 | IndexField indexField=new IndexField();
16 | indexField.setId(String.valueOf(message.getId()));
17 | indexField.setTitle(message.getTitle());
18 | indexField.setContent(message.getContent());
19 | indexField.setAddTime(message.getAddTime());
20 | try {
21 | File f=new File(message.getAttachUrl());
22 | if(f.exists()){
23 | indexField.setSummary(new Tika().parseToString(f));
24 | }
25 | } catch (IOException e) {
26 | e.printStackTrace();
27 | } catch (TikaException e) {
28 | e.printStackTrace();
29 | }
30 | return indexField;
31 | }
32 |
33 | }
34 |
--------------------------------------------------------------------------------
/src/com/luo/util/LuceneContext.java:
--------------------------------------------------------------------------------
1 | package com.luo.util;
2 |
3 | import java.io.File;
4 | import java.io.IOException;
5 |
6 | import org.apache.lucene.index.CorruptIndexException;
7 | import org.apache.lucene.index.IndexWriter;
8 | import org.apache.lucene.index.IndexWriterConfig;
9 | import org.apache.lucene.search.IndexSearcher;
10 | import org.apache.lucene.search.NRTManager;
11 | import org.apache.lucene.search.NRTManagerReopenThread;
12 | import org.apache.lucene.search.SearcherManager;
13 | import org.apache.lucene.search.SearcherWarmer;
14 | import org.apache.lucene.store.Directory;
15 | import org.apache.lucene.store.FSDirectory;
16 | import org.apache.lucene.util.Version;
17 |
18 | import com.chenlb.mmseg4j.analysis.MMSegAnalyzer;
19 |
20 | /**
21 | * 完全实时搜索,只要数据库有变动,立即更新索引
22 | * 近实时搜索,当有数据变动,先把索引保存到内存中,然后在一个统一时间提交
23 | * 使用NRTManager(near-real-time)和SearcherManager
24 | * @author 罗辉, @date:Aug 5, 2013
25 | *
26 | */
27 | public class LuceneContext {
28 | private static LuceneContext luceneContext=null;
29 | private static String INDEX_DIR="G:/lucene/solr/home/data/index";
30 | private static Version VERSION = Version.LUCENE_35;
31 | private static Directory directory;
32 | private static MMSegAnalyzer analyzer;
33 | private static IndexWriter indexWriter;
34 | private static NRTManager nrtManager;
35 | private static SearcherManager searcherManager;
36 | private LuceneContext() {
37 | }
38 |
39 |
40 | /**
41 | * 注意:使用searcherManager的acquire()方法来获取IndexSearcher
42 | *
43 | * Author:罗辉 ,Date:Aug 5, 2013
44 | */
45 | public static IndexSearcher getSearcher() {
46 | return searcherManager.acquire();
47 | }
48 | public static LuceneContext getContext() {
49 | if(luceneContext==null){
50 | init();
51 | new LuceneContext();
52 | }
53 | return luceneContext;
54 | }
55 |
56 |
57 | private static void init() {
58 | try {
59 | directory = FSDirectory.open(new File(INDEX_DIR));
60 | String dicDir = LuceneContext.class.getResource("data").getPath();
61 | analyzer = new MMSegAnalyzer(dicDir);
62 | indexWriter=new IndexWriter(directory,new IndexWriterConfig(VERSION,analyzer));
63 | //注意,只有在lucene3.5中才有这个构造方法,如果以后运行有问题,请换成3.6
64 | nrtManager=new NRTManager(indexWriter,new SearcherWarmer(){
65 | @Override
66 | public void warm(IndexSearcher arg0) throws IOException {
67 | System.out.println("reopen index");
68 | }
69 | });
70 | searcherManager=nrtManager.getSearcherManager(true);//允许全部删除
71 | NRTManagerReopenThread thread=new NRTManagerReopenThread(nrtManager,5.0,0.025);
72 | thread.setDaemon(true);//设置为
73 | thread.setName("NRTManager Reopen Thread");
74 | thread.run();
75 | } catch (IOException e) {
76 | e.printStackTrace();
77 | }
78 | }
79 |
80 |
81 | public void commitIndex() {
82 | try {
83 | indexWriter.commit();
84 | indexWriter.forceMerge(3);
85 | }catch (IOException e) {
86 | e.printStackTrace();
87 | }
88 | }
89 | }
90 |
--------------------------------------------------------------------------------
/src/com/luo/util/PropertiesUtil.java:
--------------------------------------------------------------------------------
1 | package com.luo.util;
2 |
3 | import java.io.File;
4 | import java.io.FileInputStream;
5 | import java.io.IOException;
6 | import java.io.InputStream;
7 | import java.util.Properties;
8 |
9 | import org.springframework.stereotype.Component;
10 |
11 | @Component("myPropertiesUtil")
12 | public class PropertiesUtil {
13 | private static Properties properties=null;
14 |
15 |
16 | static{
17 | try {
18 | properties=new Properties();
19 | File file = new File(PropertiesUtil.class.getResource("/").getPath());
20 | File[] fs=file.listFiles();
21 | for (File f : fs) {
22 | if(f.isFile()&&f.getName().endsWith("properties")){
23 | properties.load(new FileInputStream(f));
24 | }
25 | }
26 | System.out.println("properties初始化。。。。。。。。");
27 | System.out.println(properties.get("uploadDir"));
28 | } catch (IOException e) {
29 | e.printStackTrace();
30 | }
31 | }
32 |
33 | public static String get(String key){
34 | return properties.getProperty(key);
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/src/com/luo/util/ReflectUtil.java:
--------------------------------------------------------------------------------
1 | package com.luo.util;
2 |
3 | import java.lang.reflect.ParameterizedType;
4 | import java.lang.reflect.Type;
5 |
6 | public class ReflectUtil {
7 |
8 | @SuppressWarnings("rawtypes")
9 | public static Class getGenericParmeterType(Class clazz) {
10 | Type type = clazz.getGenericSuperclass();
11 | ParameterizedType pt = (ParameterizedType) type;
12 | Type[] types = pt.getActualTypeArguments();
13 | return (Class>) types[0];
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/src/com/luo/util/SolrContext.java:
--------------------------------------------------------------------------------
1 | package com.luo.util;
2 |
3 | import java.net.MalformedURLException;
4 | import org.apache.solr.client.solrj.SolrServer;
5 | import org.apache.solr.client.solrj.impl.CommonsHttpSolrServer;
6 |
7 | public class SolrContext {
8 | private static final String url="http://localhost:8080/solr";
9 | private static CommonsHttpSolrServer server=null;
10 |
11 |
12 | static{
13 | try {
14 | server=new CommonsHttpSolrServer(url);//创建solrServer
15 | } catch (MalformedURLException e) {
16 | e.printStackTrace();
17 | }
18 | }
19 |
20 | public static SolrServer getServer(){
21 | return server;
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/src/com/luo/vo/IndexField.java:
--------------------------------------------------------------------------------
1 | package com.luo.vo;
2 |
3 | import java.util.Date;
4 |
5 | import org.apache.solr.client.solrj.beans.Field;
6 |
7 | /**
8 | * 索引Bean
9 | * @author 罗辉, @date:Aug 2, 2013
10 | *
11 | */
12 | public class IndexField {
13 |
14 | private String id;//或者直接在属性上加@Field
15 | private String title;
16 | private String summary;
17 | private String content;
18 | private Date addTime;
19 | public String getId() {
20 | return id;
21 | }
22 |
23 | @Field
24 | public void setId(String id) {
25 | this.id = id;
26 | }
27 | public String getTitle() {
28 | return title;
29 | }
30 | @Field
31 | public void setTitle(String title) {
32 | this.title = title;
33 | }
34 | public String getSummary() {
35 | return summary;
36 | }
37 | @Field("description")
38 | public void setSummary(String summary) {
39 | this.summary = summary;
40 | }
41 | public String getContent() {
42 | return content;
43 | }
44 | @Field
45 | public void setContent(String content) {
46 | this.content = content;
47 | }
48 | public Date getAddTime() {
49 | return addTime;
50 | }
51 | @Field("last_modified")//千万要注意加在setter上,否则就会报Invalid setter method. Must have one and only one parameter
52 | public void setAddTime(Date addTime) {
53 | this.addTime = addTime;
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/src/com/luo/vo/IndexModel.java:
--------------------------------------------------------------------------------
1 | package com.luo.vo;
2 |
3 | import java.util.Date;
4 |
5 | /**
6 | * lucene模型,用于在页面展示
7 | * @author 罗辉, @date:2013-8-1
8 | *
9 | */
10 | public class IndexModel {
11 | private String id;
12 | private String title;
13 | private String summary;
14 | private String content;
15 | private Date addTime;
16 |
17 | public String getId() {
18 | return id;
19 | }
20 | public void setId(String id) {
21 | this.id = id;
22 | }
23 | public String getTitle() {
24 | return title;
25 | }
26 | public void setTitle(String title) {
27 | this.title = title;
28 | }
29 | public String getSummary() {
30 | return summary;
31 | }
32 | public void setSummary(String summary) {
33 | this.summary = summary;
34 | }
35 | public String getContent() {
36 | return content;
37 | }
38 | public void setContent(String content) {
39 | this.content = content;
40 | }
41 | public Date getAddTime() {
42 | return addTime;
43 | }
44 | public void setAddTime(Date addTime) {
45 | this.addTime = addTime;
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/src/com/taiping/b2b2e/common/page/PageBean.java:
--------------------------------------------------------------------------------
1 | package com.taiping.b2b2e.common.page;
2 |
3 | import java.util.ArrayList;
4 | import java.util.List;
5 |
6 |
7 | public class PageBean{
8 |
9 | private static final long serialVersionUID = -9135374123948501729L;
10 |
11 | private int totalRows; // 记录总数
12 |
13 | private int pageSize = 10;
14 |
15 | private int currentPage; // 当前页
16 |
17 | private int totalPages; // 总页数
18 |
19 | private int startRow; // 开始行
20 |
21 | /**
22 | * 当前页结果集
23 | */
24 | private List resultList = new ArrayList();
25 |
26 | public PageBean(int _totalRows) {
27 | totalRows = _totalRows;
28 | totalPages = totalRows / pageSize;
29 | int mod = totalRows % pageSize;
30 | if (mod > 0) {
31 | totalPages++;
32 | }
33 | currentPage = 1;
34 | startRow = 0;
35 | }
36 |
37 | public PageBean(int _totalRows,int _pageSize) {
38 | totalRows = _totalRows;
39 | pageSize = _pageSize;
40 | totalPages = totalRows / pageSize;
41 | int mod = totalRows % pageSize;
42 | if (mod > 0) {
43 | totalPages++;
44 | }
45 | currentPage = 1;
46 | startRow = 0;
47 | }
48 |
49 | public int getStartRow() {
50 | return startRow;
51 | }
52 |
53 | public int getTotalPages() {
54 | return totalPages;
55 | }
56 |
57 | public int getCurrentPage() {
58 | return currentPage;
59 | }
60 |
61 | public int getPageSize() {
62 | return pageSize;
63 | }
64 |
65 | public void setTotalRows(int totalRows) {
66 | this.totalRows = totalRows;
67 | }
68 |
69 | public void setStartRow(int startRow) {
70 | this.startRow = startRow;
71 | }
72 |
73 | public void setTotalPages(int totalPages) {
74 | this.totalPages = totalPages;
75 | }
76 |
77 | public void setCurrentPage(int currentPage) {
78 | this.currentPage = currentPage;
79 | }
80 |
81 | public void setPageSize(int pageSize) {
82 | this.pageSize = pageSize;
83 | }
84 |
85 | public int getTotalRows() {
86 | return totalRows;
87 | }
88 |
89 | public void first() {
90 | currentPage = 1;
91 | startRow = 0;
92 | }
93 |
94 | public void previous() {
95 | if (currentPage == 1) {
96 | return;
97 | }
98 | if(currentPage==0){
99 | currentPage=1;
100 | return;
101 | }
102 | currentPage--;
103 | startRow = (currentPage - 1) * pageSize;
104 | }
105 |
106 | public void next() {
107 | if (currentPage < totalPages) {
108 | currentPage++;
109 | }
110 | startRow = (currentPage - 1) * pageSize;
111 | }
112 |
113 | public void last() {
114 | currentPage = totalPages;
115 | startRow = (currentPage - 1) * pageSize;
116 | }
117 |
118 | public void refresh(int _currentPage) {
119 | currentPage = _currentPage==0?1:_currentPage;
120 | if (currentPage > totalPages) {
121 | last();
122 | }
123 | }
124 |
125 | public void gotoPage(int goPage) {
126 | if(goPage < 1)
127 | goPage = 1;
128 | else if(goPage > totalPages)
129 | goPage = totalPages;
130 |
131 | currentPage = goPage;
132 | startRow = (currentPage - 1) * pageSize;
133 | }
134 |
135 | public List getResultList() {
136 | return resultList;
137 | }
138 |
139 | public void setResultList(List resultList) {
140 | this.resultList = resultList;
141 | }
142 | }
143 |
--------------------------------------------------------------------------------