Authored by hugufei

添加productbaseindex索引

package com.yoho.search.consumer.index.fullbuild;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import com.yoho.search.consumer.index.common.IIndexBuilder;
import com.yoho.search.dal.ProductMapper;
import com.yoho.search.dal.model.Product;
@Component
public class ProductBaseIndexBuilder extends IIndexBuilder {
@Autowired
private ProductMapper productMapper;
@Override
public int getTotalCount() throws Exception {
return productMapper.selectCount();
}
@Override
public List<?> getPageLists(int offset, int limit) throws Exception {
List<Product> productList = productMapper.selectPageLists(offset, limit);
if (productList.isEmpty()) {
return new ArrayList<Map<String, Object>>();
}
List<Map<String, Object>> dataList = new ArrayList<Map<String, Object>>();
for (Product product : productList) {
dataList.add(this.getProductBaseMap(product));
}
return dataList;
}
private Map<String, Object> getProductBaseMap(Product product) {
Map<String, Object> productMap = new HashMap<String, Object>();
productMap.put("id", product.getId());
productMap.put("productSkn", product.getErpProductId());
productMap.put("productName", product.getProductName());
productMap.put("shopId", product.getShopId());
productMap.put("brandId", product.getBrandId());
productMap.put("maxSortId", product.getMaxSortId());
productMap.put("middleSortId", product.getMiddleSortId());
productMap.put("smallSortId", product.getSmallSortId());
productMap.put("phrase", product.getPhrase());
productMap.put("firstShelveTime", product.getFirstShelveTime());
return productMap;
}
@Override
public String getId(Object object) {
return ((Map<?, ?>) object).get("id").toString();
}
}
... ...
index.analysis.analyzer.default.type: keyword
\ No newline at end of file
... ...
{
"productbaseindex": {
"_all":{
"enabled":false
},
"_source":{
"enabled":true
},
"properties": {
"id": {
"type": "integer"
},
"productSkn": {
"type": "integer"
},
"productName": {
"type": "text",
"analyzer": "standard"
},
"shopId": {
"type": "integer"
},
"brandId": {
"type": "integer"
},
"firstShelveTime": {
"type": "integer"
},
"maxSortId": {
"type": "integer"
},
"middleSortId": {
"type": "smallSortId"
},
"firstShelveTime": {
"type": "integer"
},
"phrase": {
"type": "text",
"index": "no"
}
}
}
}
\ No newline at end of file
... ...
... ... @@ -84,6 +84,19 @@
<mappingFile>esmapping/productindex.json</mappingFile>
<analysisFile>analysis/productindex.yml</analysisFile>
</index>
<index>
<name>productbaseindex</name>
<properties>
<property key="number_of_shards" value="1"/>
<property key="number_of_replicas" value="1"/>
<property key="refresh_interval" value="10s"/>
<property key="translog.flush_threshold_size" value="100mb"/>
</properties>
<builderClass>com.yoho.search.consumer.index.fullbuild.ProductBaseIndexBuilder</builderClass>
<mappingFile>esmapping/productbaseindex.json</mappingFile>
<analysisFile>analysis/productbaseindex.yml</analysisFile>
</index>
<index>
<name>suggest</name>
... ...
... ... @@ -84,6 +84,19 @@
<mappingFile>esmapping/productindex.json</mappingFile>
<analysisFile>analysis/productindex.yml</analysisFile>
</index>
<index>
<name>productbaseindex</name>
<properties>
<property key="number_of_shards" value="1"/>
<property key="number_of_replicas" value="${search.index.number_of_replicas}"/>
<property key="refresh_interval" value="${search.index.refresh_interval}"/>
<property key="translog.flush_threshold_size" value="${search.index.translog.flush_threshold_size}"/>
</properties>
<builderClass>com.yoho.search.consumer.index.fullbuild.ProductBaseIndexBuilder</builderClass>
<mappingFile>esmapping/productbaseindex.json</mappingFile>
<analysisFile>analysis/productbaseindex.yml</analysisFile>
</index>
<index>
<name>suggest</name>
... ...