添加商品数据

Spring容器

由Spring容器,来管理SolrServer
将SolrServer注入Spring容器

添加配置文件
applicationContext-solr.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"xmlns:context="http://www.springframework.org/schema/context" xmlns:p="http://www.springframework.org/schema/p"xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsdhttp://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsdhttp://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.2.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.2.xsdhttp://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.2.xsd"><!-- 单机版solr的连接 --><bean id="httpSolrServer" class="org.apache.solr.client.solrj.impl.HttpSolrServer"><constructor-arg name="baseURL" value="http://192.168.25.154:8080/solr/collection1"/></bean><!-- 集群版solr连接 --><!-- <bean id="cloudSolrServer" class="org.apache.solr.client.solrj.impl.CloudSolrServer"><constructor-arg name="zkHost" value="192.168.25.154:2181,192.168.25.154:2182,192.168.25.154:2183"></constructor-arg><property name="defaultCollection" value="collection2"/></bean> --></beans>

ServerImpl

业务逻辑

1、查询所有商品数据
2、创建一个SolrServer对象
3、为每个商品创建一个SolrInputDocument对象
4、为文档添加域
5、向索引库中添加文档
6、返回TaotaoResult

@Service
public class SearchItemServiceImpl implements SearchItemService {@Autowiredprivate SearchItemMapper searchItemMapper;@Autowiredprivate SolrServer solrServer;@Overridepublic TaotaoResult importItemsToIndex() {try {//1、先查询所有商品数据List<SearchItem> itemList = searchItemMapper.getItemList();//2、遍历商品数据添加到索引库for (SearchItem searchItem : itemList) {//创建文档对象SolrInputDocument document = new SolrInputDocument();//向文档中添加域document.addField("id", searchItem.getId());document.addField("item_title", searchItem.getTitle());document.addField("item_sell_point", searchItem.getSell_point());document.addField("item_price", searchItem.getPrice());document.addField("item_image", searchItem.getImage());document.addField("item_category_name", searchItem.getCategory_name());document.addField("item_desc", searchItem.getItem_desc());//把文档写入索引库solrServer.add(document);}//3、提交solrServer.commit();} catch (Exception e) {e.printStackTrace();return TaotaoResult.build(500, "数据导入失败");}//4、返回添加成功return TaotaoResult.ok();}}

如果,采用Dubbo分布式服务
需要发布服务

<!-- 声明需要暴露的服务接口 -->
<dubbo:service interface="com.taotao.search.service.SearchItemService" ref="searchItemServiceImpl" timeout="300000"/>

调用的模块,引用服务

<!-- 引用dubbo服务 -->
<dubbo:reference interface="com.taotao.search.service.SearchItemService" id="searchItemService" />

SolrJ添加商品数据相关推荐

  1. (转)淘淘商城系列——导入商品数据到索引库——Service层

    http://blog.csdn.net/yerenyuan_pku/article/details/72894187 通过上文的学习,我相信大家已经学会了如何使用Solrj来操作索引库.本文我们将把 ...

  2. 百万级商品数据实时同步,查询结果秒出

    来自:微微科技公司 前阵子老板安排了一个新任务,要建设一个商家商品搜索系统,能够为用户提供快速.准确的搜索能力,在用户输入搜索内容时,要能从商家名称和商品名称两个维度去搜索,搜索出来的结果,按照准确率 ...

  3. 分布式爬虫系统设计、实现与实战:爬取京东、苏宁易购全网手机商品数据+MySQL、HBase存储...

    http://blog.51cto.com/xpleaf/2093952 1 概述 在不用爬虫框架的情况,经过多方学习,尝试实现了一个分布式爬虫系统,并且可以将数据保存到不同地方,类似MySQL.HB ...

  4. ActiveMQ添加商品接收消息

    Destination 配置信息 <!-- 配置消息的Destination对象 --> <bean id="test-queue" class="or ...

  5. ActiveMQ添加商品发送消息

    添加商品 需要同步索引库,同步缓存,生成静态页面等等 很多地方,都需要监听添加商品的事件,所以,这里使用Topic模式 方案选择 方案一:直接写业务逻辑 在商品服务模块,添加商品的业务逻辑中,添加同步 ...

  6. 基于Redis优化购物车 - 添加商品

    @ApiOperation(value = "添加商品到购物车", notes = "添加商品到购物车", httpMethod = "POST&qu ...

  7. GZFramwork快速开发框架演练之会员系统(四)添加商品管理

    1.1:创建表结构 新建三张商品关联的表,表模型如下: 创建SQL语句略 1.2:生成表Model(生成方法见上一节) 1.3:生成tb_ProductType的单结构界面然后添加到项目中 1.4:修 ...

  8. ECSHOP批量添加商品到购物车

    Ecshop是一款开源的网上商店系统,在我心目中可以算得上网上商城界的Wordpress了. 本文介绍如何实现在ecshop中批量添加商品到购物车. 大家都知道,默认的ecshop只能单件点击&quo ...

  9. 第37课 thinkphp5添加商品基本信息及通过前置钩子上传商品主图 模型事件(勾子函数)...

    目录 手册地址: before_insert(新增之前的操作) 要实现的功能 思路 触发条件: 1. 控制器里必须要调用模型的save()方式保存数据,用insert()触发不了勾子函数的 2. 模型 ...

最新文章

  1. 模板方法模式与策略模式的区别
  2. 挑战 Intel 和英伟达,高通发布 Cloud AI 100 边缘推理芯片
  3. UA MATH563 概率论的数学基础I 概率空间1 基本概念
  4. [问答]-EL1t和EL1h中的后缀t和h分别是什么意思
  5. UNION 和UNION ALL的区别
  6. 如何简单的测试kubernetes的dns add-ons是否工作正常?
  7. [五]RabbitMQ-客户端源码之AMQChannel
  8. .NET Core使用skiasharp文字头像生成方案(基于docker发布)
  9. P3273-[SCOI2011]棘手的操作【线段树,并查集】
  10. python入门到实践试题及答案_python编程:入门到实践练习答案
  11. Springboot项目固化依赖的那点事
  12. ASP.NET对验证控件的一些整理(一)
  13. 如何设置硬盘安装linux,linux用硬盘安装时所设置选项
  14. 简单的php商城,简单的php商城
  15. linux双机热备软件Rose,Linux Rose HA 双机热备软件原理
  16. Clover 驱动文件夹_通过AppleALC,轻松解决苹果声卡驱动的问题.
  17. macfee怎么生成释放代码_批处理应用:使用FLASHGET检查Mcafee SuperDat更新
  18. arcgis 批量计算几何_ArcGIS四种计算图斑面积的方法
  19. 对不起,免费午餐现在只提供稀饭了-- MSN停止支持对第三方软件的登录请求
  20. 2019DeeCamp夏令营总结

热门文章

  1. jQuery选择器整理
  2. 直接取HANA数据库数据,动态QUERY
  3. 浅谈JS的数组遍历方法
  4. 【hihocoder】三十九周:二分.归并排序之逆序对
  5. VS2017 运行VS2013项目
  6. 蓝牙HCI剖析(二)
  7. 人工智能到底是什么?人工智能如何改变社会?中国的人工智能应该做怎样的探索?
  8. 自然语言处理库——TextBlob
  9. cmake (2)build方面的指令
  10. C++ Primer 5th笔记(chap 14 重载运算和类型转换)标准库函数对象