淘淘商城系列(九)solr导入索引库

本文章来自我的博客:http://iclyj.cn/blog/articles/98.html


根据上一篇的solr服务器的搭建完成先创建一个测试类测试一下


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
@Test
     public  void  testSolrJ()  throws  Exception {
             //创建连接
             SolrServer solrServer =  new  HttpSolrServer( "http://192.168.0.103:8080/solr" );
             //创建一个文档对象
             SolrInputDocument document =  new  SolrInputDocument();
             //添加域
             document.addField( "id" "solrtest01" );
             document.addField( "item_title" "测试商品" );
             document.addField( "item_sell_point" "卖点" );
             //添加到索引库
             solrServer.add(document);
             //提交
             solrServer.commit();
     }

亲测可行


创建pojo类


1500639777564049826.jpg


1500639787829033294.jpg

创建mapper接口


1500639820720021596.jpg


编写mapper.xml


1500639852751043230.jpg

修改applicationContext-dao.xml


1500639900767025586.jpg


修改applicationContext-service.xml


1500639940626045925.jpg


创建service


1500639981626007161.jpg


1500640003298085681.jpg


创建controller层


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
package  com.taotao.search.controller;
import  org.springframework.beans.factory.annotation.Autowired;
import  org.springframework.stereotype.Controller;
import  org.springframework.web.bind.annotation.RequestMapping;
import  org.springframework.web.bind.annotation.ResponseBody;
import  com.taotao.common.pojo.TaotaoResult;
import  com.taotao.search.service.ItemService;
import  com.taotaocommon.util.ExceptionUtil;
/**
  * 导入索引库
  * @author lyj
  *
  */
@Controller
public  class  ItemController {
     @Autowired
     private  ItemService itemService;
     
     @RequestMapping ( "/importall" )
     @ResponseBody
     public  TaotaoResult importALL(){
       
         try  {
             TaotaoResult result= itemService.importItems();
             return  result;
         catch  (Exception e) {
             e.printStackTrace();
             return  TaotaoResult.build( 500 , ExceptionUtil.getStackTrace(e));
         }
     }
}

测试:localhost:8083/search/importall

返回200即成功


1500640357814027745.jpg



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值