forked from sdksdk0/taotaoMalls
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
335 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/META-INF |
2 changes: 1 addition & 1 deletion
2
...manager-web/src/main/webapp/META-INF/maven/cn.tf.taotao/taotao-manager-web/pom.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/META-INF |
2 changes: 1 addition & 1 deletion
2
taotao-portal/src/main/webapp/META-INF/maven/cn.tf.taotao/taotao-portal/pom.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
taotao-rest/src/main/webapp/META-INF/maven/cn.tf.taotao/taotao-rest/pom.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
taotao-search/src/main/java/cn/tf/taotao/search/controller/ItemController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package cn.tf.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 cn.tf.taotao.common.utils.ExceptionUtil; | ||
import cn.tf.taotao.common.utils.TaotaoResult; | ||
import cn.tf.taotao.search.service.ItemService; | ||
|
||
@Controller | ||
@RequestMapping("/manager") | ||
public class ItemController { | ||
|
||
@Autowired | ||
private ItemService itemService; | ||
|
||
/** | ||
* 导入商品数据库到索引库 | ||
*/ | ||
@RequestMapping("/importAll") | ||
@ResponseBody | ||
public TaotaoResult importAllItems() { | ||
TaotaoResult result = itemService.importAllItems(); | ||
return result; | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
taotao-search/src/main/java/cn/tf/taotao/search/controller/SearchController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package cn.tf.taotao.search.controller; | ||
|
||
import org.apache.commons.lang3.StringUtils; | ||
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.RequestMethod; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
import org.springframework.web.bind.annotation.ResponseBody; | ||
|
||
import cn.tf.taotao.common.utils.ExceptionUtil; | ||
import cn.tf.taotao.common.utils.TaotaoResult; | ||
import cn.tf.taotao.search.pojo.SearchResult; | ||
import cn.tf.taotao.search.service.SearchService; | ||
|
||
|
||
//商品查询 | ||
@Controller | ||
public class SearchController { | ||
|
||
@Autowired | ||
private SearchService searchService; | ||
|
||
@RequestMapping(value="/query",method=RequestMethod.GET) | ||
@ResponseBody | ||
public TaotaoResult search(@RequestParam("q") String queryString, | ||
@RequestParam(defaultValue="1")Integer page, | ||
@RequestParam(defaultValue="40")Integer rows){ | ||
|
||
if(StringUtils.isBlank(queryString)){ | ||
return TaotaoResult.build(400, "查询条件不能为空"); | ||
} | ||
|
||
SearchResult searchResult=null; | ||
try { | ||
queryString=new String(queryString.getBytes("iso8859-1"),"utf-8"); | ||
|
||
searchResult = searchService.search(queryString, page, rows); | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
return TaotaoResult.build(500, ExceptionUtil.getStackTrace(e)); | ||
} | ||
return TaotaoResult.ok(searchResult); | ||
} | ||
|
||
} |
12 changes: 12 additions & 0 deletions
12
taotao-search/src/main/java/cn/tf/taotao/search/dao/SearchDao.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package cn.tf.taotao.search.dao; | ||
|
||
import org.apache.solr.client.solrj.SolrQuery; | ||
|
||
import cn.tf.taotao.search.pojo.SearchResult; | ||
|
||
public interface SearchDao { | ||
|
||
SearchResult searchItem(SolrQuery solrQuery) throws Exception; | ||
|
||
|
||
} |
70 changes: 70 additions & 0 deletions
70
taotao-search/src/main/java/cn/tf/taotao/search/dao/impl/SearchDaoImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package cn.tf.taotao.search.dao.impl; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
|
||
import org.apache.solr.client.solrj.SolrQuery; | ||
import org.apache.solr.client.solrj.SolrServer; | ||
import org.apache.solr.client.solrj.response.QueryResponse; | ||
import org.apache.solr.common.SolrDocument; | ||
import org.apache.solr.common.SolrDocumentList; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Repository; | ||
|
||
import cn.tf.taotao.search.dao.SearchDao; | ||
import cn.tf.taotao.search.pojo.Item; | ||
import cn.tf.taotao.search.pojo.SearchResult; | ||
|
||
//商品搜索dao | ||
@Repository | ||
public class SearchDaoImpl implements SearchDao { | ||
|
||
|
||
@Autowired | ||
private SolrServer solrServer; | ||
|
||
|
||
@Override | ||
public SearchResult searchItem(SolrQuery query) throws Exception { | ||
|
||
SearchResult result=new SearchResult(); | ||
//根据查询条件查询索引库 | ||
QueryResponse queryResponse=solrServer.query(query); | ||
SolrDocumentList solrDocumentList=queryResponse.getResults(); | ||
result.setRecordCount(solrDocumentList.getNumFound()); | ||
List<Item> itemList=new ArrayList<>(); | ||
|
||
//高亮显示 | ||
Map<String, Map<String,List<String>>> highlight=queryResponse.getHighlighting(); | ||
|
||
for (SolrDocument solrDocument : solrDocumentList) { | ||
Item item=new Item(); | ||
item.setId((String) solrDocument.get("id")); | ||
|
||
List<String>list = highlight.get(solrDocument.get("id")).get("item_title"); | ||
String title = ""; | ||
if (null != list&& !list.isEmpty()) { | ||
title = list.get(0); | ||
} else { | ||
title = (String) solrDocument.get("item_title"); | ||
} | ||
item.setTitle(title); | ||
|
||
item.setPrice((long) solrDocument.get("item_price")); | ||
item.setSell_point((String) solrDocument.get("item_sell_point")); | ||
item.setImage((String) solrDocument.get("item_image")); | ||
item.setCategory_name((String) solrDocument.get("item_category_name")); | ||
|
||
itemList.add(item); | ||
|
||
} | ||
result.setItemList(itemList); | ||
return result; | ||
|
||
} | ||
|
||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,6 @@ | |
|
||
public interface ItemMapper { | ||
|
||
List<Item> searchItemList(); | ||
List<Item> getItemList(); | ||
|
||
} |
8 changes: 5 additions & 3 deletions
8
taotao-search/src/main/java/cn/tf/taotao/search/mapper/ItemMapper.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,18 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> | ||
<mapper namespace="cn.tf.taotao.search.mapper.ItemMapper"> | ||
<select id="searchItemList" resultType="cn.tf.taotao.search.pojo.Item"> | ||
SELECT | ||
<select id="getItemList" resultType="cn.tf.taotao.search.pojo.Item"> | ||
SELECT | ||
a.id, | ||
a.title, | ||
a.sell_point, | ||
a.price, | ||
a.image, | ||
b.name category_name, | ||
c.item_desc | ||
FROM tb_item a LEFT JOIN tb_item_cat b ON a.cid=b.id LEFT JOIN tb_item_desc c ON a.id=c.item_id | ||
FROM tb_item a | ||
LEFT JOIN tb_item_cat b ON a.cid=b.id | ||
LEFT JOIN tb_item_desc c ON a.id=c.item_id | ||
|
||
</select> | ||
</mapper> |
39 changes: 39 additions & 0 deletions
39
taotao-search/src/main/java/cn/tf/taotao/search/pojo/SearchResult.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package cn.tf.taotao.search.pojo; | ||
|
||
import java.util.List; | ||
|
||
public class SearchResult { | ||
|
||
private Long recordCount; //总记录数 | ||
private List<Item>itemList; //商品列表 | ||
private long pageCount; //分页总数 | ||
private long curPage; //当前页 | ||
public Long getRecordCount() { | ||
return recordCount; | ||
} | ||
public void setRecordCount(Long recordCount) { | ||
this.recordCount = recordCount; | ||
} | ||
public List<Item> getItemList() { | ||
return itemList; | ||
} | ||
public void setItemList(List<Item> itemList) { | ||
this.itemList = itemList; | ||
} | ||
public long getPageCount() { | ||
return pageCount; | ||
} | ||
public void setPageCount(long pageCount) { | ||
this.pageCount = pageCount; | ||
} | ||
public long getCurPage() { | ||
return curPage; | ||
} | ||
public void setCurPage(long curPage) { | ||
this.curPage = curPage; | ||
} | ||
|
||
|
||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,6 @@ | |
|
||
public interface ItemService { | ||
|
||
TaotaoResult importAllItems() throws Exception; | ||
TaotaoResult importAllItems(); | ||
|
||
} |
10 changes: 10 additions & 0 deletions
10
taotao-search/src/main/java/cn/tf/taotao/search/service/SearchService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package cn.tf.taotao.search.service; | ||
|
||
import org.apache.solr.client.solrj.SolrQuery; | ||
|
||
import cn.tf.taotao.search.pojo.SearchResult; | ||
|
||
public interface SearchService { | ||
|
||
SearchResult search(String queryString,int page,int rows) throws Exception; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.