当前位置: 首页 > news >正文

太仓住房城乡建设网站长沙3合1网站建设电话

太仓住房城乡建设网站,长沙3合1网站建设电话,wordpress安装包文件夹,石狮市网站建设学习了一下https://github.com/TyCoding/ssm-redis-solr这个github上的solr搜索功能#xff0c;现在来记录一下。 我的理解就是solr有点类似于数据库#xff0c;但它是有索引的数据库#xff0c;按很多字段建立索引#xff0c;可能是b树或者散列索引#xff0c;然后就能够…  学习了一下https://github.com/TyCoding/ssm-redis-solr这个github上的solr搜索功能现在来记录一下。 我的理解就是solr有点类似于数据库但它是有索引的数据库按很多字段建立索引可能是b树或者散列索引然后就能够实现海量数据的查找。solr通过导入jar包就可以对这个库就行增删改查了后端逃不掉的增删改查。。。  1.配置tomcat 具体我就不说了因为我是直接用了github上配置好的毕竟站在巨人的肩膀上学习嘛 地址https://github.com/TyCoding/solr-tomcat 2.访问solr并使用 访问端口:localhost:8080/solr/index.html 这里的new_core就是项目中配置的路径就将商品的索引放在这里。 然后用Test测试它的使用测试的时候要引入配置文件不然会导致空指针错误我居然现在才知道。怪不得以前只要用Autowired的时候就会空指针错误。。而且还要Runwith注解引入包import org.springframework.test.context.junit4.*;eclipse点击不会有import提示需要自己加上去。    这里新建了一个实体对象然后把这个实体对象加入到索引库里在solr索引库里面就可以找到这个字段 在new_core的schema里面就以Id建好了索引 以及很多的信息 Testpublic void testFindById() {Goods goods solrTemplate.getById(1, Goods.class);System.out.println(-------- goods.getTitle());} 通过id查找控制台会输出你刚刚插入的数据也就是通过solrTemplate找到了你的数据。 Testpublic void testAddList() {ListGoods list new ArrayListGoods();//循环插入100条数据for (int i 0; i 100; i) {BigDecimal pricenew BigDecimal (2.3);Goods goods new Goods(i 1L, 华为Mate i,price, 手机, 手机, 华为专卖店);list.add(goods);}solrTemplate.saveBeans(list); //添加集合对象调用saveBeans()添加普通对象类型数据使用saveBean();solrTemplate.commit(); //提交} 还可以批量插入数据或者分页查询 Testpublic void testPageQuery() {Query query new SimpleQuery(*:*);query.setOffset(20); //开始索引默认0query.setRows(20); //每页记录数默认10ScoredPageGoods page solrTemplate.queryForPage(query, Goods.class);System.out.println(总记录数 page.getTotalElements());ListGoods list page.getContent();} 3.学习一下项目中怎么配置 注意要在web.xml加一个过滤不然注入不了solrTemplate这个bean   spring-solr.xml ?xml version1.0 encodingUTF-8? beans xmlnshttp://www.springframework.org/schema/beansxmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexmlns:solrhttp://www.springframework.org/schema/data/solrxsi:schemaLocationhttp://www.springframework.org/schema/data/solrhttp://www.springframework.org/schema/data/solr/spring-solr-1.0.xsdhttp://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans.xsd!-- solr服务器地址 --solr:solr-server idsolrServer urlhttp://127.0.0.1:8080/solr/new_core/!-- solr模板使用solr模板可对索引库进行CRUD的操作 --bean idsolrTemplate classorg.springframework.data.solr.core.SolrTemplateconstructor-arg refsolrServer//bean/beans 就是加载一个solr的模板   SolrUtil.java 把数据库的数据库批量加入 Component public class SolrUtil {Autowiredprivate GoodsMapper goodsMapper;Autowiredprivate SolrTemplate solrTemplate;/*** 实现将数据库中的数据批量导入到Solr索引库中*/public void importGoodsData() {ListGoods list goodsMapper.findAll();System.out.println(商品列表);for (Goods goods : list) {System.out.println(goods.getTitle());}solrTemplate.saveBeans(list);solrTemplate.commit(); //提交System.out.println(结束);}public static void main(String[] args) {ApplicationContext context new ClassPathXmlApplicationContext(classpath:spring/spring*.xml);SolrUtil solrUtil (SolrUtil) context.getBean(solrUtil);solrUtil.importGoodsData();} }    这样就把数据加入索引库中。 实体类有一个Field标识这个实体字段在索引库里的名称 Fieldprivate Long id; //商品IDField(item_title)private String title; //商品标题Field(item_price)private BigDecimal price; //商品价格Field(item_image)private String image; //商品图片Field(item_category)private String category; //商品类别Field(item_brand)private String brand; //商品品牌Field(item_seller)private String seller; //商品卖家 最后搜索功能的实现 按价格查找 //按价格区间查询if (searchMap.get(price) ! null) {if (!searchMap.get(price).equals()) {String[] price ((String) searchMap.get(price)).split(-);if (!price[0].equals(0)) {//如果起点区间不等于0Criteria filterCriteria new Criteria(item_price).greaterThanEqual(price[0]);FilterQuery filterQuery new SimpleFilterQuery(filterCriteria);query.addFilterQuery(filterQuery);}if (!price[1].equals(*)) {//如果区间重点不等于*Criteria filterCriteria new Criteria(item_price).lessThanEqual(price[1]);FilterQuery filterQuery new SimpleFilterQuery(filterCriteria);query.addFilterQuery(filterQuery);}}}  4.实现效果  转载于:https://www.cnblogs.com/HannahLihui/p/10104416.html
http://www.huolong8.cn/news/118662/

相关文章:

  • 浙江怎么制作网站包装设计一键生成器
  • 网站建设网站软件有哪些内容莱芜都市网招聘
  • 个人网站备案需要哪些材料做外汇看哪些网站数据
  • 文山知名网站建设报价公司网站建设管理意见
  • 北京电商网站开发价格长沙设计公司都有哪些
  • 巩义做网站xd seo如何做竞价网站
  • 建网站多少费用精品展厅设计
  • 深圳网站建设高端设计个人养老金制度具体内容
  • 北京做兼职从哪个网站公司网站的后台
  • 商城建站流程电商网站有哪些平台
  • 深圳网站建设 设计科技有限公司网站服务器租用价格多少钱一年
  • 杭州建设项目审批网站头像制作免费模板
  • 信息网站有哪些专业订制网站制作
  • 心理咨询中心网站模板网站建设的基本准则是什么
  • 为国外客户做网站建设游戏app制作
  • 安徽智能网站建设推荐凡客诚品官方网店下载
  • 网站开发 思维导图企业融资只有两种方法
  • 响应式网站做法厦门医院网站建设
  • 国家城乡建设规划部网站园林景观设计公司经营范围
  • 北京网站建设小程序开发帝国网站建设
  • 企业网站的开发襄阳软件开发
  • 哈尔滨寸金网站建设价格广州网站建设藤虎网络
  • 国企怎么做网站wordpress贴内幻灯片
  • 网站模板下载带后台专业做棋牌网站的
  • 网站开发费用报价单页面设计步骤
  • 网站设计网页版流量推广是什么意思
  • 做网站要钱的吗西咸新区建设环保网站
  • 如何做盆栽蔬菜网站专业网页设计价格
  • 中山有网站建设公司吗社区教育网站建设方案
  • 风景网站模板网站开发怎么使用维语