Authored by hugufei

新版本召回机制代码优化

... ... @@ -6,6 +6,7 @@ import com.yoho.search.recall.scene.component.*;
import com.yoho.search.recall.scene.models.*;
import com.yoho.search.recall.scene.persional.PersionalFactor;
import com.yoho.search.recall.scene.persional.RecallPersionalService;
import com.yoho.search.service.helper.SearchCommonHelper;
import org.apache.commons.collections.MapUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
... ... @@ -32,6 +33,8 @@ public class SceneRecallService {
private BatchResponseBuilder batchResponseBuilder;
@Autowired
private RecallResultBuilder recallResultBuilder;
@Autowired
private SearchCommonHelper searchCommonHelper;
public SearchApiResult sceneRecall(Map<String, String> paramMap) {
try {
... ... @@ -50,13 +53,12 @@ public class SceneRecallService {
//TODO
//5、构造返回结果
JSONObject dataMap = new JSONObject();
dataMap.put("recallResult",recallResult);
// dataMap.put("total", recallResult.getTotal());
// dataMap.put("page", recallResult.getPage());
// dataMap.put("page_size", recallResult.getPageSize());
// dataMap.put("page_total", recallResult.getRecallPageTotal());
// dataMap.put("product_list", recallResult.getSknList());
// return new SearchApiResult().setData(dataMap);
dataMap.put("total", recallResult.getTotal());
dataMap.put("page", recallParams.getPage());
dataMap.put("page_size", recallParams.getPageSize());
dataMap.put("page_total", searchCommonHelper.getTotalPage(recallResult.getTotal(),recallParams.getPageSize()));
dataMap.put("product_list",recallResult);
return new SearchApiResult().setData(dataMap);
} catch (Exception e) {
logger.error(e.getMessage(), e);
return new SearchApiResult().setData(null).setCode(500).setMessage("Exception");
... ...
... ... @@ -30,7 +30,6 @@ public class RecallResultBuilder {
final long total = recallResponseBatch.getTotal();
final int page = param.getPage();
final int pageSize = param.getPageSize();
final long pageTotal = searchCommonHelper.getTotalPage(total,pageSize);
//2、获取召回结果中的最大整数页码
List<RecallResponseBatch.SknResult> sknResultList = recallResponseBatch.getSknList();
... ... @@ -69,9 +68,10 @@ public class RecallResultBuilder {
recallMaxPage = 5;
}
sknResultList = CollectionUtils.safeSubList(sknResultList,0,recallMaxPage * pageSize);
final long recallTotal = sknResultList.size();
//8、判断当前页码是否在召回结果中
int realPage = page;
int realPage;
List<Integer> sknList = null;
List<Integer> notProductSkn = null;
... ... @@ -82,7 +82,7 @@ public class RecallResultBuilder {
realPage = page;
sknList = this.getSknList(CollectionUtils.safeSubList(sknResultList,(page-1)*pageSize,page *pageSize));
}
return new RecallResult(total,page,pageSize,pageTotal,realPage,sknList,notProductSkn);
return new RecallResult(total,recallTotal,recallMaxPage,realPage,sknList,notProductSkn);
}
private void doCalScore(List<RecallResponseBatch.SknResult> sknResultList,PersionalFactor persionalFactor) {
... ...
... ... @@ -4,19 +4,14 @@ import java.util.List;
public class RecallResult {
private final long total;
private final int page;
private final int pageSize;
private final long recallTotal;
private final long recallPageTotal;
private final int realPage;
private final List<Integer> sknList;
private final List<Integer> notProductSkn;
public RecallResult(long total,int page, int pageSize,long recallTotal,long recallPageTotal, int realPage,List<Integer> sknList,List<Integer> notProductSkn) {
public RecallResult(long total,long recallTotal,long recallPageTotal, int realPage,List<Integer> sknList,List<Integer> notProductSkn) {
this.total = total;
this.page = page;
this.pageSize = pageSize;
this.recallTotal = recallTotal;
this.recallPageTotal = recallPageTotal;
this.realPage = realPage;
... ... @@ -28,14 +23,6 @@ public class RecallResult {
return total;
}
public int getPage() {
return page;
}
public int getPageSize() {
return pageSize;
}
public long getRecallTotal() {
return recallTotal;
}
... ...