(六)通过solr7的API实现商品的列表查询
(六)通过solr7的API实现商品的列表查询
工具类:
获取 HttpSolrClient
public class Constant {
public static HttpSolrClient getSolrClient() {
HttpSolrClient solrServer= new HttpSolrClient.Builder("http://127.0.0.1:8080/solr/core1").build();
return solrServer;
}
}
jsp表单:
<form id="actionForm" action="serch.do" method="POST">
<div class="form">
<input type="text" class="text" accesskey="s" name="queryString" id="key" value="${queryString }"
autocomplete="off" onkeydown="javascript:if(event.keyCode==13) {query()}">
<input type="button" value="搜索" class="button" onclick="query()">
</div>
<input type="hidden" name="catalog_name" id="catalog_name" value="${catalog_name }"/>
<input type="hidden" name="price" id="price" value="${price }"/>
<input type="hidden" name="page" id="page" value="${page }"/>
<input type="hidden" name="sort" id="sort" value="${sort }"/>
</form>
Controller控制层:
//搜索
@RequestMapping("/serch.do")
public String serchProduct(String queryString,String catalog_name,Integer price,String page,String sort ,Model model) throws Exception{
Result result = productService.querylist(queryString,catalog_name,price,page,sort);
System.out.println(result);
model.addAttribute("result", result);
model.addAttribute("queryString",queryString);
model.addAttribute("商品",catalog_name);
System.out.println("访问成功");
return "product_list";
}
service层,没有dao层这里直接在service查询solr,童鞋可以自己使用dao:
//主列表查询
public Result querylist(String qName, String catalog_name, Integer price, String page, String sort) throws Exception {
HttpSolrClient solrServer = Constant.getSolrClient();
//使用solrQuery封装查询条件
SolrQuery solrQuery = new SolrQuery(); //封装主查询条件
if(qName!=null && !qName.equals("")){
//solrQuery.setQuery(qName);
//关键词 商品名称
solrQuery.setQuery("p_name:" + qName+"");//^10是查询权重 solrQuery.setStart();
solrQuery.setRows();
//开启高亮
solrQuery.setHighlight(true);
solrQuery.addHighlightField("p_name");
solrQuery.setHighlightSimplePre("<font color='red'>");
solrQuery.setHighlightSimplePost("</font>");
}else{
solrQuery.setStart();
solrQuery.setRows();
solrQuery.setQuery("*:*");
} QueryResponse resp = solrServer.query(solrQuery);
Map<String, Map<String, List<String>>> highlighting = resp.getHighlighting();
SolrDocumentList results = resp.getResults();
Result result = new Result();
List<Product> pList = result.getProductList();
for (SolrDocument doc : results) {
Product product = new Product();
System.out.println(doc.getFieldValuesMap());
String id = (String) doc.get("id");//id
Integer product_number = Integer.parseInt(doc.get("p_number")+"");//数量
String product_name = (String) doc.get("p_name");//商品名称
Double product_price = (Double.parseDouble(doc.get("p_price")+"")) ;//价格
String product_catalog_name = (String) doc.get("p_catalog_name");//商品分类名称
String product_picture = (String) doc.get("p_picture");//图片 //商品ID
product.setPid(Integer.valueOf(id));
//商品名称
if (null!=highlighting) {
Map<String, List<String>> map = highlighting.get(id);
List<String> list = map.get("p_name");
//String name = (String) doc.get("name_ik");
product.setName(list.get());
}else {
product.setName(product_name);
} //图片
product.setPicture(product_picture);
//价格
product.setPrice(product_price);
//品牌ID
product.setCatalogName(product_catalog_name);
//商品数量
product.setNumber(product_number);
pList.add(product);
}
result.setProductList(pList);
return result;
}
(六)通过solr7的API实现商品的列表查询的更多相关文章
- MyBatis(六):Mybatis Java API编程实现一对多、一对一
最近工作中用到了mybatis的Java API方式进行开发,顺便也整理下该功能的用法,接下来会针对基本部分进行学习: 1)Java API处理一对多.多对一的用法: 2)增.删.改.查的用法: 3) ...
- 【SSH系列】一步步深入springmvc+商品列表查询demo
在前面的博文中,小编主要简单的介绍springmvc的体系结构.mvc模式的优缺点以及mvc框架,今天我们来继续学习springmvc的相关知识,在这篇博文中,小编讲解过springmvc的体系结构, ...
- 写个简单的chrome插件-京东商品历史价格查询
说chrome插件编写的先关文章, 首推小茗的[干货]Chrome插件(扩展)开发全攻略. 有非常完善的理论,引用和demo代码. 但是还是建议看官方的 chrome extensions. chro ...
- 商城02——dubbo框架整合_商品列表查询实现_分页
1. 课程计划 1.服务中间件dubbo 2.SSM框架整合. 3.测试使用dubbo 4.后台系统商品列表查询功能实现. 5.监控中心的搭建 2. 功能分析 2.1. 后台系统所用的技术 框 ...
- TFS API : 四、工作项查询
TFS API : 四.工作项查询 本节将讲述如何查询工作项,将用户统计数据. 使用WorkItemStore.Query方法进行查询工作项,其使用的语法和SQL语法类似: Select [标题] f ...
- [翻译]在ASP.NET Web API中通过OData支持查询和分页
OData可以通过形如http://localhost/Products?$orderby=Name这样的QueryString传递查询条件.排序等.你可以在任何Web API Controller中 ...
- ArcGIS api for javascript——加载查询结果,悬停显示信息窗口
转自原文 ArcGIS api for javascript——加载查询结果,悬停显示信息窗口 描述 本例在开始和地图交互前执行一个查询任务并加在查询结果.这允许用户鼠标悬停在任意郡县时立即见到Inf ...
- Lucene系列六:Lucene搜索详解(Lucene搜索流程详解、搜索核心API详解、基本查询详解、QueryParser详解)
一.搜索流程详解 1. 先看一下Lucene的架构图 由图可知搜索的过程如下: 用户输入搜索的关键字.对关键字进行分词.根据分词结果去索引库里面找到对应的文章id.根据文章id找到对应的文章 2. L ...
- ABP源码分析三十六:ABP.Web.Api
这里的内容和ABP 动态webapi没有关系.除了动态webapi,ABP必然是支持使用传统的webApi.ABP.Web.Api模块中实现了一些同意的基础功能,以方便我们创建和使用asp.net w ...
随机推荐
- [转]2年SQL Server DBA调优方面总结
2年SQL Server DBA调优方面总结 当2年dba 我觉得,有些东西需要和大家分享探讨,先书单. 书单 1.<深入解析SQL Server 2008 系列> 这个就是mssql ...
- [BestCoder Round #3] hdu 4908 BestCoder Sequence (计数)
BestCoder Sequence Problem Description Mr Potato is a coder. Mr Potato is the BestCoder. One night, ...
- Unity 导出切片精灵
http://blog.csdn.net/akof1314/article/details/38845933 设有一张png/tga图集,导入到Unity,放置目录"Assets/Resou ...
- 使用Nginx+uWSGI+Django方法部署Django程序(上)
Django的部署可以有很多方式,采用nginx+uwsgi的方式是其中比较常见的一种方式. 在这种方式中,我们的通常做法是,将nginx作为服务器最前端,它将接收WEB的所有请求,统一管理请求.ng ...
- 解析式/推导式, 生成器 datetime 内建函数
列表解析式(List Comprehension) 语法: [返回值 for 元素 in 可迭代对象 if 条件] 使用中括号[],内部是for循环,if条件可选. 返回一个新的列表. 列表解析式的作 ...
- asp.net mvc 重定向
protected override void OnActionExecuting(ActionExecutingContext filterContext) { if (Request.Cookie ...
- 前端模块化和AMD、CMD规范
前端模块化和AMD.CMD规范 先看下基础:https://github.com/seajs/seajs/issues/547
- Atitit hre框架v5 新特性 HREv5
Atitit hre框架v5 新特性 HREv5 1. V5新特性 apiurl2="/wrmiServlet";1 2. V1 新特性1 3. V2 新特性 添加php版1 ...
- 【算法拾遗(java描写叙述)】--- 插入排序(直接插入排序、希尔排序)
插入排序基本思想 每次将一个待排序的记录按其keyword大小插入到前面已经拍好序的子文件的适当位置,直到全部记录插入完毕为止. 直接插入排序 基本思想 直接插入排序的基本操作是将一个记录插入到已排好 ...
- JavaScript Creating 对象
可通过多种方法在 JavaScript 中创建你自己的对象.可以直接实例化Object 对象 (JavaScript),然后添加你自己的属性和方法.或者可以使用对象文本表示法来定义你的对象.还可使用构 ...