Showing
1 changed file
with
18 additions
and
2 deletions
@@ -2,12 +2,15 @@ package com.yoho.search.service.service; | @@ -2,12 +2,15 @@ package com.yoho.search.service.service; | ||
2 | 2 | ||
3 | import java.text.SimpleDateFormat; | 3 | import java.text.SimpleDateFormat; |
4 | import java.util.ArrayList; | 4 | import java.util.ArrayList; |
5 | +import java.util.Collections; | ||
6 | +import java.util.Comparator; | ||
5 | import java.util.HashMap; | 7 | import java.util.HashMap; |
6 | import java.util.HashSet; | 8 | import java.util.HashSet; |
7 | import java.util.List; | 9 | import java.util.List; |
8 | import java.util.Map; | 10 | import java.util.Map; |
9 | import java.util.Set; | 11 | import java.util.Set; |
10 | 12 | ||
13 | +import org.apache.commons.collections.MapUtils; | ||
11 | import org.apache.commons.lang.StringUtils; | 14 | import org.apache.commons.lang.StringUtils; |
12 | import org.elasticsearch.action.get.GetResponse; | 15 | import org.elasticsearch.action.get.GetResponse; |
13 | import org.elasticsearch.action.get.MultiGetItemResponse; | 16 | import org.elasticsearch.action.get.MultiGetItemResponse; |
@@ -208,12 +211,25 @@ public class SearchCommonService implements ApplicationEventPublisherAware { | @@ -208,12 +211,25 @@ public class SearchCommonService implements ApplicationEventPublisherAware { | ||
208 | } | 211 | } |
209 | } | 212 | } |
210 | } else if (indexName.equals(ISearchConstants.INDEX_NAME_SIZE)) { | 213 | } else if (indexName.equals(ISearchConstants.INDEX_NAME_SIZE)) { |
214 | + List<Map<String, Object>> sizeResults = new ArrayList<Map<String, Object>>(); | ||
211 | for (MultiGetItemResponse item : response.getResponses()) { | 215 | for (MultiGetItemResponse item : response.getResponses()) { |
212 | if (item.getResponse().isExists()) { | 216 | if (item.getResponse().isExists()) { |
213 | - tmpMap = item.getResponse().getSource(); | ||
214 | - list.add(getSizeMap(tmpMap)); | 217 | + sizeResults.add(item.getResponse().getSource()); |
218 | + } | ||
219 | + } | ||
220 | + //按orderby排序 | ||
221 | + Collections.sort(sizeResults,new Comparator<Map<String, Object>>(){ | ||
222 | + @Override | ||
223 | + public int compare(Map<String, Object> size1, Map<String, Object> size2) { | ||
224 | + int orderBy1 = MapUtils.getIntValue(size1, "orderBy"); | ||
225 | + int orderBy2 = MapUtils.getIntValue(size2, "orderBy"); | ||
226 | + return (orderBy1 - orderBy2) * (-1); | ||
215 | } | 227 | } |
228 | + }); | ||
229 | + for (Map<String, Object> sizeResult : sizeResults) { | ||
230 | + list.add(getSizeMap(sizeResult)); | ||
216 | } | 231 | } |
232 | + | ||
217 | } else if (indexName.equals(ISearchConstants.INDEX_NAME_STYLE)) { | 233 | } else if (indexName.equals(ISearchConstants.INDEX_NAME_STYLE)) { |
218 | for (MultiGetItemResponse item : response.getResponses()) { | 234 | for (MultiGetItemResponse item : response.getResponses()) { |
219 | if (item.getResponse().isExists()) { | 235 | if (item.getResponse().isExists()) { |
-
Please register or login to post a comment