Authored by Gino Zhang

调整suggest_word的插入顺序

@@ -5,68 +5,72 @@ package com.yoho.search.consumer.suggests.common; @@ -5,68 +5,72 @@ package com.yoho.search.consumer.suggests.common;
5 */ 5 */
6 public enum KeywordType { 6 public enum KeywordType {
7 7
8 - BrandName(1, 8, SuggestionConstants.BRANDNAME_ENABLED_KEY),  
9 - ShopName(7, 8, SuggestionConstants.SHOPNAME_ENABLED_KEY),  
10 - SortName(2, 8, SuggestionConstants.SORTNAME_ENABLED_KEY), 8 + BrandName(1, 8, SuggestionConstants.BRANDNAME_ENABLED_KEY),
  9 + ShopName(7, 8, SuggestionConstants.SHOPNAME_ENABLED_KEY),
  10 + SortName(2, 8, SuggestionConstants.SORTNAME_ENABLED_KEY),
11 11
12 - BrandWithSortName(11, 7, SuggestionConstants.BRANDWITHSORTNAME_ENABLED_KEY),  
13 - TblBrandName(9, 7, SuggestionConstants.BRANDNAME_ENABLED_KEY),  
14 - TblSortName(10, 7, SuggestionConstants.SORTNAME_ENABLED_KEY),  
15 -  
16 - ProductNameToken(4, 6, SuggestionConstants.PRODUCTNAME_TOKEN_ENABLED_KEY),  
17 - ProductKeywordToken(5, 6,SuggestionConstants.PRODUCTKEYWORD_TOKEN_ENABLED_KEY),  
18 - BrandKeywordToken(6, 6, SuggestionConstants.BRANDKEYWORD_TOKEN_ENABLED_KEY), 12 + BrandWithSortName(11, 7, SuggestionConstants.BRANDWITHSORTNAME_ENABLED_KEY),
  13 + TblBrandName(9, 7, SuggestionConstants.BRANDNAME_ENABLED_KEY),
  14 + TblSortName(10, 7, SuggestionConstants.SORTNAME_ENABLED_KEY),
19 15
20 - StyleName(13, 4, SuggestionConstants.STYLENAME_ENABLED_KEY),  
21 - ParameterMake(12, 3, SuggestionConstants.PARAMETERMAKE_ENABLED_KEY), 16 + StyleName(13, 7, SuggestionConstants.STYLENAME_ENABLED_KEY),
  17 + ParameterMake(12, 7, SuggestionConstants.PARAMETERMAKE_ENABLED_KEY),
22 18
23 - ProductName(8, 1, SuggestionConstants.PRODUCTNAME_ENABLED_KEY),  
24 - Customized(0, 1),  
25 - HotKeyword(3, 0,SuggestionConstants.HOTKEYWORD_ENABLED_KEY); 19 + ProductNameToken(4, 6, SuggestionConstants.PRODUCTNAME_TOKEN_ENABLED_KEY),
  20 + ProductKeywordToken(5, 6, SuggestionConstants.PRODUCTKEYWORD_TOKEN_ENABLED_KEY),
  21 + BrandKeywordToken(6, 6, SuggestionConstants.BRANDKEYWORD_TOKEN_ENABLED_KEY),
26 22
27 - private KeywordType(int type, int weightValue) {  
28 - this.type = type;  
29 - this.weightValue = weightValue;  
30 - } 23 + ProductName(8, 1, SuggestionConstants.PRODUCTNAME_ENABLED_KEY),
  24 + Customized(0, 1),
  25 + HotKeyword(3, 0, SuggestionConstants.HOTKEYWORD_ENABLED_KEY);
31 26
32 - private KeywordType(int type, int weightValue, String globleEnabledKey) {  
33 - this(type, weightValue);  
34 - this.globleEnabledKey = globleEnabledKey;  
35 - } 27 + private KeywordType(int type, int weightValue) {
  28 + this.type = type;
  29 + this.weightValue = weightValue;
  30 + }
36 31
37 - private int type;  
38 - private int weightValue;  
39 - private String globleEnabledKey; 32 + private KeywordType(int type, int weightValue, String globleEnabledKey) {
  33 + this(type, weightValue);
  34 + this.globleEnabledKey = globleEnabledKey;
  35 + }
40 36
41 - public int getType() {  
42 - return this.type;  
43 - } 37 + private int type;
  38 + private int weightValue;
  39 + private String globleEnabledKey;
44 40
45 - public String getGlobleEnabledKey() {  
46 - return this.globleEnabledKey;  
47 - } 41 + public int getType() {
  42 + return this.type;
  43 + }
48 44
49 - public int getWeightValue() {  
50 - return this.weightValue;  
51 - }  
52 -  
53 - /**  
54 - * 值越大,越排在前面  
55 - *  
56 - * @param other  
57 - * @return  
58 - */  
59 - public int compare(KeywordType other) {  
60 - return (this.weightValue - other.getWeightValue()) * (-1);  
61 - }  
62 -  
63 - public static int getWeightValueByType(int type){  
64 - for (KeywordType keywordType : KeywordType.values()) {  
65 - if(keywordType.getType()==type){  
66 - return keywordType.getWeightValue();  
67 - }  
68 - }  
69 - return 0;  
70 - } 45 + public String getGlobleEnabledKey() {
  46 + return this.globleEnabledKey;
  47 + }
  48 +
  49 + public int getWeightValue() {
  50 + return this.weightValue;
  51 + }
  52 +
  53 + /**
  54 + * 值越大,越排在前面
  55 + *
  56 + * @param other
  57 + * @return
  58 + */
  59 + public int compare(KeywordType other) {
  60 + if (this.weightValue != other.getWeightValue()) {
  61 + return (this.weightValue - other.getWeightValue()) * (-1);
  62 + } else {
  63 + return (this.type - other.getType()) * (-1);
  64 + }
  65 + }
  66 +
  67 + public static int getWeightValueByType(int type) {
  68 + for (KeywordType keywordType : KeywordType.values()) {
  69 + if (keywordType.getType() == type) {
  70 + return keywordType.getWeightValue();
  71 + }
  72 + }
  73 + return 0;
  74 + }
71 75
72 } 76 }