Search in sources :

Example 1 with PmsSearchSkuInfo

use of com.xatu.gmall.entity.PmsSearchSkuInfo in project GMall by 18391713434.

the class SearchServiceImpl method list.

@Override
public List<PmsSearchSkuInfo> list(PmsSearchParam pmsSearchParam) {
    String searchDsl = getSearchDsl(pmsSearchParam);
    Search search = new Search.Builder(searchDsl).addIndex("gmall").addType("PmsSkuInfo").build();
    SearchResult execute = null;
    try {
        execute = jestClient.execute(search);
    } catch (Exception e) {
        e.printStackTrace();
        System.out.println("es未查询到数据");
    }
    ArrayList<PmsSearchSkuInfo> pmsSearchSkuInfoArrayList = new ArrayList<>();
    List<SearchResult.Hit<PmsSearchSkuInfo, Void>> hits = null;
    hits = execute.getHits(PmsSearchSkuInfo.class);
    if (hits != null) {
        for (SearchResult.Hit<PmsSearchSkuInfo, Void> hit : hits) {
            PmsSearchSkuInfo source = hit.source;
            Map<String, List<String>> hightlight = hit.highlight;
            if (hightlight != null) {
                String skuName = hightlight.get("skuName").get(0);
                source.setSkuName(skuName);
            }
            pmsSearchSkuInfoArrayList.add(source);
        }
    }
    return pmsSearchSkuInfoArrayList;
}
Also used : ArrayList(java.util.ArrayList) SearchResult(io.searchbox.core.SearchResult) Search(io.searchbox.core.Search) ArrayList(java.util.ArrayList) List(java.util.List) PmsSearchSkuInfo(com.xatu.gmall.entity.PmsSearchSkuInfo)

Example 2 with PmsSearchSkuInfo

use of com.xatu.gmall.entity.PmsSearchSkuInfo in project GMall by 18391713434.

the class GmallSearchServiceApplicationTests method contextLoads.

@Test
public void contextLoads() throws IOException {
    List<PmsSkuInfo> pmsSkuInfoList = new ArrayList<>();
    pmsSkuInfoList = skuService.selectAllSku("61");
    // 转换为es数据结构
    List<PmsSearchSkuInfo> pmsSearchSkuInfoList = new ArrayList<>();
    for (PmsSkuInfo pmsSkuInfo : pmsSkuInfoList) {
        PmsSearchSkuInfo pmsSearchSkuInfo = new PmsSearchSkuInfo();
        BeanUtils.copyProperties(pmsSkuInfo, pmsSearchSkuInfo);
        pmsSearchSkuInfo.setProductId(pmsSkuInfo.getSpuId());
        pmsSearchSkuInfoList.add(pmsSearchSkuInfo);
    }
    // 导入es
    for (PmsSearchSkuInfo pmsSearchSkuInfo : pmsSearchSkuInfoList) {
        String idStr = pmsSearchSkuInfo.getId().toString();
        Index put = new Index.Builder(pmsSearchSkuInfo).index("com.xatu.gmall").type("PmsSkuInfo").id(idStr).build();
        jestClient.execute(put);
    }
}
Also used : PmsSkuInfo(com.xatu.gmall.entity.PmsSkuInfo) ArrayList(java.util.ArrayList) Index(io.searchbox.core.Index) PmsSearchSkuInfo(com.xatu.gmall.entity.PmsSearchSkuInfo) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

PmsSearchSkuInfo (com.xatu.gmall.entity.PmsSearchSkuInfo)2 ArrayList (java.util.ArrayList)2 PmsSkuInfo (com.xatu.gmall.entity.PmsSkuInfo)1 Index (io.searchbox.core.Index)1 Search (io.searchbox.core.Search)1 SearchResult (io.searchbox.core.SearchResult)1 List (java.util.List)1 Test (org.junit.Test)1 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)1