Browse Source

add sort fields: component's searchweight

sunyj 8 years ago
parent
commit
6ccce73550

+ 2 - 0
mall-search/src/main/java/com/uas/search/constant/SearchConstants.java

@@ -79,6 +79,7 @@ public class SearchConstants {
 	public static final String COMPONENT_CODE_FIELD = "cmp_code";
     public static final String COMPONENT_VISIT_COUNT_FIELD = "cmp_visit_count";
     public static final String COMPONENT_SEARCH_COUNT_FIELD = "cmp_search_count";
+    public static final String COMPONENT_WEIGHT_FIELD = "cmp_weight";
 	public static final String COMPONENT_RESERVE_FIELD = "cmp_reserve";
 	public static final String COMPONENT_SAMPLE_QTY_FIELD = "cmp_sample_qty";
 	public static final String COMPONENT_ORIGINAL_QTY_FIELD = "cmp_original_qty";
@@ -124,6 +125,7 @@ public class SearchConstants {
 	public static final String GOODS_CMP_DESCRIPTION_FIELD = "cmp_description";
     public static final String GOODS_CMP_VISIT_COUNT_FIELD = "cmp_visit_count";
     public static final String GOODS_CMP_SEARCH_COUNT_FIELD = "cmp_search_count";
+    public static final String GOODS_CMP_WEIGHT_FIELD = "cmp_weight";
 	public static final String GOODS_KI_ID_FIELD = "ki_id";
 	public static final String GOODS_KI_NAME_CN_FIELD = "ki_name_cn";
 	public static final String GOODS_KI_NAME_CN_UNTOKENIZED_FIELD = "ki_name_cn_untokenized";

+ 34 - 19
mall-search/src/main/java/com/uas/search/model/Component.java

@@ -6,7 +6,7 @@ import java.util.Set;
 
 /**
  * 器件简要信息,只用于索引的创建与查询
- * 
+ *
  * @author sunyj
  * @since 2016年7月7日 下午5:55:26
  */
@@ -98,6 +98,12 @@ public class Component implements Serializable {
 	@Column(name = "cmp_search_count")
 	private Long searchCount;
 
+    /**
+     * 搜索权重
+     */
+    @Column(name = "searchweight")
+    private Double weight;
+
 	/**
 	 * 带的属性及属性的值
 	 */
@@ -210,22 +216,31 @@ public class Component implements Serializable {
 		this.searchCount = searchCount;
 	}
 
-	@Override
-	public String toString() {
-		return "Component{" +
-				"id=" + id +
-				", uuid='" + uuid + '\'' +
-				", code='" + code + '\'' +
-				", kind=" + kind +
-				", brand=" + brand +
-				", reserve=" + reserve +
-				", sampleQty=" + sampleQty +
-				", originalQty=" + originalQty +
-				", inactionStockQty=" + inactionStockQty +
-				", description='" + description + '\'' +
-				", visitCount=" + visitCount +
-				", searchCount=" + searchCount +
-				", properties=" + properties +
-				'}';
-	}
+    public Double getWeight() {
+        return weight;
+    }
+
+    public void setWeight(Double weight) {
+        this.weight = weight;
+    }
+
+    @Override
+    public String toString() {
+        return "Component{" +
+                "id=" + id +
+                ", uuid='" + uuid + '\'' +
+                ", code='" + code + '\'' +
+                ", kind=" + kind +
+                ", brand=" + brand +
+                ", reserve=" + reserve +
+                ", sampleQty=" + sampleQty +
+                ", originalQty=" + originalQty +
+                ", inactionStockQty=" + inactionStockQty +
+                ", description='" + description + '\'' +
+                ", visitCount=" + visitCount +
+                ", searchCount=" + searchCount +
+                ", weight=" + weight +
+                ", properties=" + properties +
+                '}';
+    }
 }

+ 7 - 0
mall-search/src/main/java/com/uas/search/service/impl/SearchServiceImpl.java

@@ -357,6 +357,7 @@ public class SearchServiceImpl implements SearchService {
     private SortField[] sortComponent(String keyword) {
         // 分数 > 器件(访问量 > 搜索次数) > 品牌(权重 > 访问量 > 搜索次数) > 类目(访问量 > 搜索次数)
         return new SortField[]{
+                sortField(SearchConstants.COMPONENT_WEIGHT_FIELD, Type.DOUBLE, true, Double.MIN_VALUE),
                 sortField(SearchConstants.COMPONENT_VISIT_COUNT_FIELD, Type.LONG, true, Long.MIN_VALUE),
                 sortField(SearchConstants.COMPONENT_SEARCH_COUNT_FIELD, Type.LONG, true, Long.MIN_VALUE),
                 sortField(SearchConstants.COMPONENT_BR_WEIGHT_FIELD, Type.DOUBLE, true, Double.MIN_VALUE),
@@ -1028,6 +1029,8 @@ public class SearchServiceImpl implements SearchService {
                 sortFieldList.addAll(Arrays.asList(
                         // 降序时,默认值为最小值;升序时,默认值为最大值
                         sortField(SearchConstants.GOODS_GO_RESERVE_FIELD, Type.DOUBLE, reverse, reverse ? Double.MIN_VALUE : Double.MAX_VALUE),
+                        sortField(SearchConstants.GOODS_CMP_WEIGHT_FIELD, Type.DOUBLE, true, Double.MIN_VALUE),
+                        sortField(SearchConstants.GOODS_BR_WEIGHT_FIELD, Type.DOUBLE, true, Double.MIN_VALUE),
                         sortField(SearchConstants.GOODS_GO_MINPRICERMB_FIELD, Type.DOUBLE, false, Double.MAX_VALUE),
                         sortField(SearchConstants.GOODS_GO_MINPRICEUSD_FIELD, Type.DOUBLE, false, Double.MAX_VALUE)
                 ));
@@ -1037,6 +1040,8 @@ public class SearchServiceImpl implements SearchService {
                         // 降序时,默认值为最小值;升序时,默认值为最大值
                         sortField(SearchConstants.GOODS_GO_MINPRICERMB_FIELD, Type.DOUBLE, reverse, reverse ? Double.MIN_VALUE : Double.MAX_VALUE),
                         sortField(SearchConstants.GOODS_GO_MINPRICEUSD_FIELD, Type.DOUBLE, reverse, reverse ? Double.MIN_VALUE : Double.MAX_VALUE),
+                        sortField(SearchConstants.GOODS_CMP_WEIGHT_FIELD, Type.DOUBLE, true, Double.MIN_VALUE),
+                        sortField(SearchConstants.GOODS_BR_WEIGHT_FIELD, Type.DOUBLE, true, Double.MIN_VALUE),
                         sortField(SearchConstants.GOODS_GO_RESERVE_FIELD, Type.DOUBLE, true, Double.MIN_VALUE)
                 ));
             } else {
@@ -1045,6 +1050,8 @@ public class SearchServiceImpl implements SearchService {
         } else {
             // 默认(综合排序)
             sortFieldList.addAll(Arrays.asList(
+                    sortField(SearchConstants.GOODS_CMP_WEIGHT_FIELD, Type.DOUBLE, true, Double.MIN_VALUE),
+                    sortField(SearchConstants.GOODS_BR_WEIGHT_FIELD, Type.DOUBLE, true, Double.MIN_VALUE),
                     sortField(SearchConstants.GOODS_GO_MINPRICERMB_FIELD, Type.DOUBLE, false, Double.MAX_VALUE),
                     sortField(SearchConstants.GOODS_GO_MINPRICEUSD_FIELD, Type.DOUBLE, false, Double.MAX_VALUE),
                     sortField(SearchConstants.GOODS_GO_RESERVE_FIELD, Type.DOUBLE, true, Double.MIN_VALUE),

+ 6 - 0
mall-search/src/main/java/com/uas/search/util/DocumentToObjectUtils.java

@@ -116,6 +116,9 @@ public class DocumentToObjectUtils {
         if (!StringUtils.isEmpty(document.get(SearchConstants.COMPONENT_SEARCH_COUNT_FIELD))) {
             component.setSearchCount(Long.valueOf(document.get(SearchConstants.COMPONENT_SEARCH_COUNT_FIELD)));
         }
+        if (!StringUtils.isEmpty(document.get(SearchConstants.COMPONENT_WEIGHT_FIELD))) {
+            component.setWeight(Double.valueOf(document.get(SearchConstants.COMPONENT_WEIGHT_FIELD)));
+        }
 
 		Kind kind = new Kind();
 		kind.setId(Long.valueOf(document.get(SearchConstants.COMPONENT_KI_ID_FIELD)));
@@ -231,6 +234,9 @@ public class DocumentToObjectUtils {
         if (!StringUtils.isEmpty(document.get(SearchConstants.GOODS_CMP_SEARCH_COUNT_FIELD))) {
             component.setSearchCount(Long.valueOf(document.get(SearchConstants.GOODS_CMP_SEARCH_COUNT_FIELD)));
         }
+        if (!StringUtils.isEmpty(document.get(SearchConstants.GOODS_CMP_WEIGHT_FIELD))) {
+            component.setWeight(Double.valueOf(document.get(SearchConstants.GOODS_CMP_WEIGHT_FIELD)));
+        }
 
 		Kind kind = new Kind();
 		if (!StringUtils.isEmpty(document.get(SearchConstants.GOODS_KI_ID_FIELD))) {

+ 8 - 0
mall-search/src/main/java/com/uas/search/util/ObjectToDocumentUtils.java

@@ -155,6 +155,10 @@ public class ObjectToDocumentUtils {
 			document.add(new DoubleDocValuesField(SearchConstants.COMPONENT_SEARCH_COUNT_FIELD, component.getSearchCount()));
 			document.add(new LongField(SearchConstants.COMPONENT_SEARCH_COUNT_FIELD, component.getSearchCount(), Store.YES));
 		}
+        if (component.getWeight() != null) {
+            document.add(new DoubleDocValuesField(SearchConstants.COMPONENT_WEIGHT_FIELD, component.getWeight()));
+            document.add(new DoubleField(SearchConstants.COMPONENT_WEIGHT_FIELD, component.getWeight(), Store.YES));
+        }
 
         Kind kind = component.getKind();
         document.add(new StringField(SearchConstants.COMPONENT_KI_ID_FIELD, String.valueOf(kind.getId()), Store.YES));
@@ -311,6 +315,10 @@ public class ObjectToDocumentUtils {
 				document.add(new DoubleDocValuesField(SearchConstants.GOODS_CMP_SEARCH_COUNT_FIELD, component.getSearchCount()));
 				document.add(new LongField(SearchConstants.GOODS_CMP_SEARCH_COUNT_FIELD, component.getSearchCount(), Store.YES));
 			}
+            if (component.getWeight() != null) {
+                document.add(new DoubleDocValuesField(SearchConstants.GOODS_CMP_WEIGHT_FIELD, component.getWeight()));
+                document.add(new DoubleField(SearchConstants.GOODS_CMP_WEIGHT_FIELD, component.getWeight(), Store.YES));
+            }
 
 			Kind kind = component.getKind();
 			if (kind.getId() != null) {