通过前两篇文章,相信大家对solr都已经有所了解,今天就分享一下如何在SSM框架中使用solr,顺便简单使用一下Vue.js。
首先我的开发环境是jdk1.7,tomcat8.0,solr5.5.4,intellij idea 13.1
-
新建一个SSM工程,pom中引入solr
<dependency>
<groupId>org.apache.solr</groupId>
<artifactId>solr-solrj</artifactId>
<version>5.5.3</version>
</dependency>
2.简单配置一下spring环境
3.配置tomcat启动时启动多个实例,这步很重要,要不然用idea 启动项目solr不会启动,如图所示就行
4.启动工程验证solr是否启动成功,看到控制台打印solr启动日志以及浏览器可以访问solr Web页面说明启动成功
5.下面是今天要实现的功能,首先写如何往solr中添加实体
6.新建User实体类
7.修改solrHome/new_core/ 下managed-schema文件,添加如下内容,不需要添加id,因为id已经在上面声明过了
<field name="username" type="string" indexed="true" stored="true"/>
<field name="password" type="string" indexed="true" stored="true"/>
<field name="desc" type="string" indexed="true" stored="true"/>
<field name="age" type="int" indexed="true" stored="true"/>
8.通过bean方式添加document代码
9.根据id删除document
10.根据用户名或描述模糊查询
11.运行效果图
添加
删除
普通查询
高亮查询
以上就是solr基本使用的全部内容,希望能对您有所帮助。