Learning topic: commodity data retrieval
1.Solr cluster, SolrCloud environment, data import
(1) talk about the understanding of the object SolrCloud and the working process of data writing in SolrCloud.
SolrCloud(solr cloud) is a distributed search solution provided by Solr. SolrCloud is used when you need large-scale, fault-tolerant, distributed indexing and retrieval capabilities. SolrCloud is not needed when the index data volume of a system is small. When the index volume is large and the search request is highly concurrent, SolrCloud needs to be used to meet these needs.
(2) talk about the relationship between SolrCloud and Zookeeper cluster
SolrCloud is different from redis cluster. SolrCloud is a distributed search scheme based on Solr and Zookeeper. Its main idea is to use Zookeeper as the configuration information center of cluster.
2. Realize product information keyword search page highlight
(1) describe the steps for Solr to achieve highlighting
SearchItemServiceImpl: package com.bjsxt.ego.search.service.impl; import com.bjsxt.ego.rpc.pojo.TbItem; import com.bjsxt.ego.rpc.service.ItemService; import com.bjsxt.ego.search.dao.ItemDao; import com.bjsxt.ego.search.entity.SearchResult; import com.bjsxt.ego.search.service.SearchItemService; import org.apache.solr.client.solrj.SolrQuery; import org.apache.solr.client.solrj.SolrServer; import org.apache.solr.client.solrj.SolrServerException; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.util.StringUtils; @Service public class SearchItemServiceImpl implements SearchItemService { @Autowired SolrServer solrServer; @Autowired ItemService itemService; @Autowired ItemDao itemDao; @Override public SearchResult loadItemList(String item_keywords, Integer page) throws SolrServerException { SolrQuery query = new SolrQuery(); /*Set default query fields*/ query.set("df","item_keywords"); /*Set query criteria*/ if(!StringUtils.isEmpty(item_keywords)){ query.setQuery(item_keywords); }else{ query.set("q","*:*"); } /*Set the number of displays per page*/ Integer rows = 20; /*Set minimum page*/ if(page<1){ page = 1; } /*Set maximum page*/ Integer maxPage = 100; if(page>maxPage){ maxPage = page; } /*Set up highlights*/ query.setHighlight(true); query.addHighlightField("title"); query.setHighlightSimplePre("<font color='red'>"); query.setHighlightSimplePost("</font>"); /*Execute query to get results*/ SearchResult result = itemDao.loadItemList(query); result.setMaxpage(Long.parseLong(maxPage.toString())); return result; } @Override public TbItem selItemBuId(Long id) { return itemService.selItemById(id); } } ItemDaoImpl: package com.bjsxt.ego.search.dao.impl; import com.bjsxt.ego.search.dao.ItemDao; import com.bjsxt.ego.search.entity.Item; import com.bjsxt.ego.search.entity.SearchResult; import org.apache.solr.client.solrj.SolrQuery; import org.apache.solr.client.solrj.SolrServerException; import org.apache.solr.client.solrj.beans.DocumentObjectBinder; import org.apache.solr.client.solrj.impl.CloudSolrServer; 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 java.util.ArrayList; import java.util.List; import java.util.Map; @Repository public class ItemDaoImpl implements ItemDao { @Autowired CloudSolrServer cloudSolrServer; @Override public SearchResult loadItemList(SolrQuery query) throws SolrServerException { QueryResponse resp = cloudSolrServer.query(query); SolrDocumentList list = resp.getResults(); SearchResult result = new SearchResult(); result.setTotal(list.getNumFound()); /*Get highlighted information*/ Map<String, Map<String, List<String>>> highlighting = resp.getHighlighting(); //List<Item> itemList = new ArrayList<>(); //take docList Translate into List<Item> DocumentObjectBinder binder = new DocumentObjectBinder(); List<Item> itemList = binder.getBeans(Item.class,list); for(Item item:itemList){ String id = item.getId(); //Get highlighted data of a product information Map<String, List<String>> map = highlighting.get(id); //Get highlighted data of a field of a product List<String> title = map.get("title"); if(title!=null&&title.size()>0){ item.setTitle(title.get(0)); } } result.setList(itemList); return result; } }
(2) describe the parameter format of interval filtering query implemented by Solr
3. Realize basic information query of commodities
(1) describe the implementation of commodity basic information query
When clicking the link or picture link, a request will be sent. The parameter carried is the id of the product to query the information of the product, and the result of the query will be rendered to the foreground page.
(2) response format of basic information display picture of description commodity
@RequestMapping("/{url}") public String showPage(@PathVariable String url, String q, Model model,@RequestParam(defaultValue = "1") Integer page){ //Research business level approach String kws=null; try { kws = new String(q.getBytes("ISO-8859-1"),"UTF-8"); SearchResult result = searchItemService.loadItemList(kws,page); model.addAttribute("query", kws); model.addAttribute("itemList", result.getList()); model.addAttribute("page", page); model.addAttribute("maxpage", result.getMaxpage()); } catch (Exception e) { e.printStackTrace(); } return url; }
4. Realize the query of commodity description and lattice parameter information
(1) describe and realize the query idea of commodity description information
When loading the page, an ajax request will be sent to query the detailed information of the goods. The parameter carried is the id of the goods to query the information of the goods. The result of the query will be rendered to the front page, which will delay the display.
(2) describe the query idea of commodity specification parameter information
When you click the product specification, you will send a request to query the product specification information. The parameter you carry is the product id to query the product information, and the result of the query will be rendered to the front page.