maven项目中如何使用solr

之前写过solr的系列文章,包括对官方文档的学习和solrj的使用,但是今天想在项目中使用却发现很难将所有的知识点串联起来。
solr系列文章
所以今天从头到尾在项目中使用一下solr,记录一下步骤。

目的

实现一个文章搜索服务

第一步 启动solr服务器

参考
http://blog.csdn.net/frankcheng5143/article/details/52291176

我是windows,所以命令如下

cd solrHome(solrHome是solr的路径)
cd bin
solr.cmd start
  • 1
  • 2
  • 3
  • 1
  • 2
  • 3

maven项目中如何使用solr

第二步 创建集合(collection/core)

我们创建一个articles的集合(collection),collection和core是一个概念(后面我都会用collection或集合)

maven项目中如何使用solr

solr.cmd create -c articles
  • 1
  • 1

maven项目中如何使用solr

第三步 配置中文分词

经过第一步和第二步我们已经创建了articles集合,这时候就可以在solr的管理控制台看到创建的articles集合了。

管理控制台地址

http://127.0.0.1:8983/solr

maven项目中如何使用solr

不过不支持中文分词

测试是否支持中文分词

在core selector区域选择要测试的集合

maven项目中如何使用solr

测试步骤如下,下图是我之前配置了分词的一个collection,并对“吉林市长春药店”进行了测试。

maven项目中如何使用solr

下图是我们刚刚创建的articles集合对“吉林市长春药店”的测试。

maven项目中如何使用solr

由于我们没有配置中文分词,所以第四步选择字段类型中没有“text_ik”,我们选择了“text”,它将“吉林市长春药店”分成了七个单独的字符。

配置中文分词

1 下载资源并放在相应的目录

参考

solr6.0配置中文分词器IK Analyzer

Solr6.1配置中文分词

分词资料下载

将解分词资料里的ik-analyzer-solr5-5.x.jar拷贝到你的solr目录下的\server\solr-webapp\webapp\WEB-INF\lib目录中去,将IKAnalyzer.cfg.xml,mydict.dic(搜狗的扩展词库),stopword.dic放在你的solr目录下的\server\solr-webapp\webapp\WEB-INF\classes目录中去

maven项目中如何使用solr

maven项目中如何使用solr

2 修改相应的配置

修改刚才创建的articles集合目录下的managed-schema

maven项目中如何使用solr

<fieldType name="text_ik" class="solr.TextField">  
        <analyzer class="org.wltea.analyzer.lucene.IKAnalyzer"/>  
</fieldType>  
<field name="text_ik"  type="text_ik" indexed="true"  stored="true"  multiValued="false" />
  • 1
  • 2
  • 3
  • 4
  • 1
  • 2
  • 3
  • 4

添加在

<schema name="example-data-driven-schema" version="1.6">
  • 1
  • 1

之后

大概在48行的位置后添加

maven项目中如何使用solr

3 重新加载articles集合

maven项目中如何使用solr

在重新测试articles的中文分词,我们就会发现在FieldType中多了我们刚才添加的“text_ik”,而且可以进行中文分词。

maven项目中如何使用solr

这个时候我们的环境基本配置完成。

第四步 定义字段类型

跟数据库一样,solr也需要定义字段类型,这里我们的检索服务需要支持中文分词,所以字段类型都是第三步我们定义的中文分词类型。

这里使用Schema API来定义字段,其实solr已经帮我们定义了很多东西

Dynamic field definitions allow using convention over configuration
for fields via the specification of patterns to match field names.

我们来对一个文章定义一下它的文章标题name和文章内容content和文章发布时间createTime

public class Article {
    // 文章id
    private String id;
    // 文章分类id
    private String categoryId;
    // 作者id
    private String authorId;
    // 文章标题
    private String name;
    // 文章内容
    private String content;
    // 发布时间
    private Date createTime;
    // 省去 getter setter toString方法
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15

定义的json格式如下

{
    "add-field" : {
        "name" : "name",
        "type" : "text_ik"
    },
    "add-field" : {
        "name" : "content",
        "type" : "text_ik"
    },
    "add-field" : {
        "name" : "createTime",
        "type" : "date"
    }
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14

以POST方式提交到

http://localhost:8983/solr/articles/schema
  • 1
  • 1

maven项目中如何使用solr

提交之后我们的name和content就支持中文分词检索了。

第五步 建立索引并查询

这里用SolrJ

注意最新版的solr需要jdk1.8及以上版本

提供一个SolrJ的工具类


import java.io.IOException;

import org.apache.solr.client.solrj.SolrClient;
import org.apache.solr.client.solrj.SolrQuery;
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.beans.DocumentObjectBinder;
import org.apache.solr.client.solrj.impl.HttpSolrClient;
import org.apache.solr.client.solrj.response.QueryResponse;
import org.apache.solr.common.SolrInputDocument;

/**

  • solr工具类

* @author 程高伟
* @time 2017年5月4日下午2:00:54
*/
public class SolrUtil {
private static SolrClient client;
private static String url;
static {
url = http://localhost:8983/solr/articles;
client = new HttpSolrClient.Builder(url).build();
}

<span class="hljs-javadoc">/**
 * 保存或者更新solr数据
 * 
 *<span class="hljs-javadoctag"> @param</span> res
 */</span>
<span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> &lt;T&gt; <span class="hljs-keyword">boolean</span> <span class="hljs-title">saveSolrResource</span>(T solrEntity) {

    DocumentObjectBinder binder = <span class="hljs-keyword">new</span> DocumentObjectBinder();
    SolrInputDocument doc = binder.toSolrInputDocument(solrEntity);
    <span class="hljs-keyword">try</span> {
        client.add(doc);
        client.commit();
    } <span class="hljs-keyword">catch</span> (Exception e) {
        e.printStackTrace();
        <span class="hljs-keyword">return</span> <span class="hljs-keyword">false</span>;
    }
    <span class="hljs-keyword">return</span> <span class="hljs-keyword">true</span>;
}

<span class="hljs-javadoc">/**
 * 删除solr 数据
 * 
 *<span class="hljs-javadoctag"> @param</span> id
 */</span>
<span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">boolean</span> <span class="hljs-title">removeSolrData</span>(String id) {
    <span class="hljs-keyword">try</span> {
        client.deleteById(id);
        client.commit();
    } <span class="hljs-keyword">catch</span> (Exception e) {
        e.printStackTrace();
        <span class="hljs-keyword">return</span> <span class="hljs-keyword">false</span>;
    }
    <span class="hljs-keyword">return</span> <span class="hljs-keyword">true</span>;
}
 <span class="hljs-javadoc">/**
 * 查询
 * 
 *<span class="hljs-javadoctag"> @param</span> keywords
 */</span>
<span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> QueryResponse <span class="hljs-title">query</span>(String keywords) <span class="hljs-keyword">throws</span> SolrServerException, IOException {
    SolrQuery query = <span class="hljs-keyword">new</span> SolrQuery();
    query.setQuery(keywords);
    QueryResponse rsp = client.query(query);
    <span class="hljs-keyword">return</span> rsp;
}

}

  • 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
  • 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

这里首先要在Article实体的字段上加上solr的注解

public class Article {
    // 文章id
    @Field
    private String id;
    // 文章分类id
    private String categoryId;
    // 作者id
    private String authorId;
    // 文章标题
    @Field
    private String name;
    // 文章内容
    @Field
    private String content;
    // 发布时间
    @Field
    private Date createTime;
    // 省去 getter setter toString方法
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19

然后我们调用SolrUtil的saveSolrResource插入几条数据

    Article article = new Article();
    article.setId(UUIDGenerator.getUUID());
    article.setName("solr测试1");
    article.setContent("吉林市长春药店");
    article.setCreateTime(new Date());
    SolrUtil.saveSolrResource(article);
    try {
        QueryResponse respone = SolrUtil.query("药店");
        List<Article> articleList = respone.getBeans(Article.class);
        System.out.println(articleList);
    } catch (SolrServerException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15

maven项目中如何使用solr

高亮显示

参考

Solr6.4.2查询&高亮

首先需要高亮显示的字段在manage-schema中指定的field中的属性store设置为true后。

我们在第四步中的add-field没有设置store

{
    "add-field" : {
        "name" : "name",
        "type" : "text_ik"
    },
    "add-field" : {
        "name" : "content",
        "type" : "text_ik"
    },
    "add-field" : {
        "name" : "createTime",
        "type" : "date"
    }
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14

在控制台看managed-schema 结果如下

maven项目中如何使用solr

所以先把name和content删掉

删掉方法

提交下面的json

{
    "delete-field" : {
        "name" : "name"
    },
    "delete-field" : {
        "name" : "content"
    }
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

以POST方式提交到

http://localhost:8983/solr/articles/schema
  • 1
  • 1

maven项目中如何使用solr

重新创建一下name和content

{
    "add-field" : {
        "name" : "name",
        "type" : "text_ik",
        "stored" : "true"
    },
    "add-field" : {
        "name" : "content",
        "type" : "text_ik",
        "stored" : "true"
    }
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12

以POST方式提交到

http://localhost:8983/solr/articles/schema
  • 1
  • 1

这个时候name和content已经重建了

maven项目中如何使用solr

控制台的高亮

maven项目中如何使用solr

勾选了hl

就可以高亮显示了

hl.fl (指定要高亮显示的字段,用空格或逗号隔开的字段列表,要启用某个字段的highlight功能,就得保证该字段在schema中是stored。)

Specifies a list of fields to highlight. Accepts a comma- or
space-delimited list of fields for which Solr should generate highlighted
snippets. A wildcard of ’ ’ (asterisk) can be used to match field globs, *
such as ‘text_*’ or even ‘*’ to highlight on all fields where highlighting is
possible. When using ‘*’, consider adding hl.requireFieldMatch=
true

hl.simple.pre(高亮前缀)
hl.simple.post(高亮后缀)

会将高亮字段以前后缀包围,这里用红色字体

在高亮是查询必须指定字段

不指定查询字段

maven项目中如何使用solr

指定查询字段

maven项目中如何使用solr

高亮查询的java代码

来自Solr6.4.2查询&高亮

public static void queryHighlight(String keywords) throws SolrServerException, IOException {
        SolrQuery solrQuery = new SolrQuery();
        solrQuery.setQuery("name:" + keywords + "or content:" + keywords); // 设置查询关键字
        solrQuery.setHighlight(true); // 开启高亮
        solrQuery.addHighlightField("name"); // 高亮字段
        solrQuery.addHighlightField("content"); // 高亮字段
        solrQuery.setHighlightSimplePre("<font color='red'>"); // 高亮单词的前缀
        solrQuery.setHighlightSimplePost("</font>"); // 高亮单词的后缀
        /**
         * hl.snippets
         * hl.snippets参数是返回高亮摘要的段数,因为我们的文本一般都比较长,含有搜索关键字的地方有多处,如果hl.snippets的值大于1的话,
         * 会返回多个摘要信息,即文本中含有关键字的几段话,默认值为1,返回含关键字最多的一段描述。solr会对多个段进行排序。
         * hl.fragsize
         * hl.fragsize参数是摘要信息的长度。默认值是100,这个长度是出现关键字的位置向前移6个字符,再往后100个字符,取这一段文本。
         */
        solrQuery.setHighlightFragsize(15);
    QueryResponse query = client.query(solrQuery);
    SolrDocumentList results = query.getResults();
    NamedList&lt;Object&gt; response = query.getResponse();
    NamedList&lt;?&gt; highlighting = (NamedList&lt;?&gt;) response.get(<span class="hljs-string">"highlighting"</span>);
    <span class="hljs-keyword">for</span> (<span class="hljs-keyword">int</span> i = <span class="hljs-number">0</span>; i &lt; highlighting.size(); i++) {
        System.out.println(highlighting.getName(i) + <span class="hljs-string">":"</span> + highlighting.getVal(i));
    }
    <span class="hljs-keyword">for</span> (SolrDocument result : results) {
        System.out.println(result.toString());
    }
}</code><ul class="pre-numbering"><li style="color: rgb(153, 153, 153);">1</li><li style="color: rgb(153, 153, 153);">2</li><li style="color: rgb(153, 153, 153);">3</li><li style="color: rgb(153, 153, 153);">4</li><li style="color: rgb(153, 153, 153);">5</li><li style="color: rgb(153, 153, 153);">6</li><li style="color: rgb(153, 153, 153);">7</li><li style="color: rgb(153, 153, 153);">8</li><li style="color: rgb(153, 153, 153);">9</li><li style="color: rgb(153, 153, 153);">10</li><li style="color: rgb(153, 153, 153);">11</li><li style="color: rgb(153, 153, 153);">12</li><li style="color: rgb(153, 153, 153);">13</li><li style="color: rgb(153, 153, 153);">14</li><li style="color: rgb(153, 153, 153);">15</li><li style="color: rgb(153, 153, 153);">16</li><li style="color: rgb(153, 153, 153);">17</li><li style="color: rgb(153, 153, 153);">18</li><li style="color: rgb(153, 153, 153);">19</li><li style="color: rgb(153, 153, 153);">20</li><li style="color: rgb(153, 153, 153);">21</li><li style="color: rgb(153, 153, 153);">22</li><li style="color: rgb(153, 153, 153);">23</li><li style="color: rgb(153, 153, 153);">24</li><li style="color: rgb(153, 153, 153);">25</li><li style="color: rgb(153, 153, 153);">26</li><li style="color: rgb(153, 153, 153);">27</li><li style="color: rgb(153, 153, 153);">28</li></ul><ul class="pre-numbering" style=""><li style="color: rgb(153, 153, 153);">1</li><li style="color: rgb(153, 153, 153);">2</li><li style="color: rgb(153, 153, 153);">3</li><li style="color: rgb(153, 153, 153);">4</li><li style="color: rgb(153, 153, 153);">5</li><li style="color: rgb(153, 153, 153);">6</li><li style="color: rgb(153, 153, 153);">7</li><li style="color: rgb(153, 153, 153);">8</li><li style="color: rgb(153, 153, 153);">9</li><li style="color: rgb(153, 153, 153);">10</li><li style="color: rgb(153, 153, 153);">11</li><li style="color: rgb(153, 153, 153);">12</li><li style="color: rgb(153, 153, 153);">13</li><li style="color: rgb(153, 153, 153);">14</li><li style="color: rgb(153, 153, 153);">15</li><li style="color: rgb(153, 153, 153);">16</li><li style="color: rgb(153, 153, 153);">17</li><li style="color: rgb(153, 153, 153);">18</li><li style="color: rgb(153, 153, 153);">19</li><li style="color: rgb(153, 153, 153);">20</li><li style="color: rgb(153, 153, 153);">21</li><li style="color: rgb(153, 153, 153);">22</li><li style="color: rgb(153, 153, 153);">23</li><li style="color: rgb(153, 153, 153);">24</li><li style="color: rgb(153, 153, 153);">25</li><li style="color: rgb(153, 153, 153);">26</li><li style="color: rgb(153, 153, 153);">27</li><li style="color: rgb(153, 153, 153);">28</li></ul></pre>

maven项目中如何使用solr

参考文献

Solr官方文档6.5

Solr系列文章

Solr6.4.2查询&高亮

        </div>
					<link href="https://csdnimg.cn/release/phoenix/mdeditor/markdown_views-8cccb36679.css" rel="stylesheet">
            </div>

之前写过solr的系列文章,包括对官方文档的学习和solrj的使用,但是今天想在项目中使用却发现很难将所有的知识点串联起来。
solr系列文章
所以今天从头到尾在项目中使用一下solr,记录一下步骤。

目的

实现一个文章搜索服务

第一步 启动solr服务器

参考
http://blog.csdn.net/frankcheng5143/article/details/52291176

我是windows,所以命令如下

cd solrHome(solrHome是solr的路径)
cd bin
solr.cmd start
  • 1
  • 2
  • 3
  • 1
  • 2
  • 3

maven项目中如何使用solr

第二步 创建集合(collection/core)

我们创建一个articles的集合(collection),collection和core是一个概念(后面我都会用collection或集合)

maven项目中如何使用solr

solr.cmd create -c articles
  • 1
  • 1

maven项目中如何使用solr

第三步 配置中文分词

经过第一步和第二步我们已经创建了articles集合,这时候就可以在solr的管理控制台看到创建的articles集合了。

管理控制台地址

http://127.0.0.1:8983/solr

maven项目中如何使用solr

不过不支持中文分词

测试是否支持中文分词

在core selector区域选择要测试的集合

maven项目中如何使用solr

测试步骤如下,下图是我之前配置了分词的一个collection,并对“吉林市长春药店”进行了测试。

maven项目中如何使用solr

下图是我们刚刚创建的articles集合对“吉林市长春药店”的测试。

maven项目中如何使用solr

由于我们没有配置中文分词,所以第四步选择字段类型中没有“text_ik”,我们选择了“text”,它将“吉林市长春药店”分成了七个单独的字符。

配置中文分词

1 下载资源并放在相应的目录

参考

solr6.0配置中文分词器IK Analyzer

Solr6.1配置中文分词

分词资料下载

将解分词资料里的ik-analyzer-solr5-5.x.jar拷贝到你的solr目录下的\server\solr-webapp\webapp\WEB-INF\lib目录中去,将IKAnalyzer.cfg.xml,mydict.dic(搜狗的扩展词库),stopword.dic放在你的solr目录下的\server\solr-webapp\webapp\WEB-INF\classes目录中去

maven项目中如何使用solr

maven项目中如何使用solr

2 修改相应的配置

修改刚才创建的articles集合目录下的managed-schema

maven项目中如何使用solr

<fieldType name="text_ik" class="solr.TextField">  
        <analyzer class="org.wltea.analyzer.lucene.IKAnalyzer"/>  
</fieldType>  
<field name="text_ik"  type="text_ik" indexed="true"  stored="true"  multiValued="false" />
  • 1
  • 2
  • 3
  • 4
  • 1
  • 2
  • 3
  • 4

添加在

<schema name="example-data-driven-schema" version="1.6">
  • 1
  • 1

之后

大概在48行的位置后添加

maven项目中如何使用solr

3 重新加载articles集合

maven项目中如何使用solr

在重新测试articles的中文分词,我们就会发现在FieldType中多了我们刚才添加的“text_ik”,而且可以进行中文分词。

maven项目中如何使用solr

这个时候我们的环境基本配置完成。

第四步 定义字段类型

跟数据库一样,solr也需要定义字段类型,这里我们的检索服务需要支持中文分词,所以字段类型都是第三步我们定义的中文分词类型。

这里使用Schema API来定义字段,其实solr已经帮我们定义了很多东西

Dynamic field definitions allow using convention over configuration
for fields via the specification of patterns to match field names.

我们来对一个文章定义一下它的文章标题name和文章内容content和文章发布时间createTime

public class Article {
    // 文章id
    private String id;
    // 文章分类id
    private String categoryId;
    // 作者id
    private String authorId;
    // 文章标题
    private String name;
    // 文章内容
    private String content;
    // 发布时间
    private Date createTime;
    // 省去 getter setter toString方法
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15

定义的json格式如下

{
    "add-field" : {
        "name" : "name",
        "type" : "text_ik"
    },
    "add-field" : {
        "name" : "content",
        "type" : "text_ik"
    },
    "add-field" : {
        "name" : "createTime",
        "type" : "date"
    }
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14

以POST方式提交到

http://localhost:8983/solr/articles/schema
  • 1
  • 1

maven项目中如何使用solr

提交之后我们的name和content就支持中文分词检索了。

第五步 建立索引并查询

这里用SolrJ

注意最新版的solr需要jdk1.8及以上版本

提供一个SolrJ的工具类


import java.io.IOException;

之前写过solr的系列文章,包括对官方文档的学习和solrj的使用,但是今天想在项目中使用却发现很难将所有的知识点串联起来。
solr系列文章
所以今天从头到尾在项目中使用一下solr,记录一下步骤。