Commit e537917c authored by D's avatar D Committed by GitHub

Merge pull request #12221 from b3log/master

rebase
parents 51568eec 6d5abec9
...@@ -16,7 +16,10 @@ ...@@ -16,7 +16,10 @@
package org.b3log.solo.repository.impl; package org.b3log.solo.repository.impl;
import java.text.Collator;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List; import java.util.List;
import javax.inject.Inject; import javax.inject.Inject;
import org.b3log.solo.model.Tag; import org.b3log.solo.model.Tag;
...@@ -32,6 +35,7 @@ import org.b3log.latke.repository.annotation.Repository; ...@@ -32,6 +35,7 @@ import org.b3log.latke.repository.annotation.Repository;
import org.b3log.latke.util.CollectionUtils; import org.b3log.latke.util.CollectionUtils;
import org.b3log.solo.repository.TagArticleRepository; import org.b3log.solo.repository.TagArticleRepository;
import org.json.JSONArray; import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
...@@ -45,6 +49,8 @@ import org.json.JSONObject; ...@@ -45,6 +49,8 @@ import org.json.JSONObject;
@Repository @Repository
public class TagRepositoryImpl extends AbstractRepository implements TagRepository { public class TagRepositoryImpl extends AbstractRepository implements TagRepository {
private final static Comparator<Object> CHINA_COMPARE = Collator.getInstance(java.util.Locale.CHINA);
/** /**
* Public constructor. * Public constructor.
*/ */
...@@ -75,12 +81,15 @@ public class TagRepositoryImpl extends AbstractRepository implements TagReposito ...@@ -75,12 +81,15 @@ public class TagRepositoryImpl extends AbstractRepository implements TagReposito
@Override @Override
public List<JSONObject> getMostUsedTags(final int num) throws RepositoryException { public List<JSONObject> getMostUsedTags(final int num) throws RepositoryException {
final Query query = new Query().addSort(Tag.TAG_PUBLISHED_REFERENCE_COUNT, SortDirection.DESCENDING).setCurrentPageNum(1).setPageSize(num).setPageCount( final Query query = new Query().addSort(Tag.TAG_PUBLISHED_REFERENCE_COUNT, SortDirection.DESCENDING).setCurrentPageNum(1).setPageSize(num).setPageCount(
1); 1);
final JSONObject result = get(query); final JSONObject result = get(query);
final JSONArray array = result.optJSONArray(Keys.RESULTS); final JSONArray array = result.optJSONArray(Keys.RESULTS);
return CollectionUtils.jsonArrayToList(array); List<JSONObject> tagJoList = CollectionUtils.jsonArrayToList(array);
sortJSONTagList(tagJoList);
return tagJoList;
} }
@Override @Override
...@@ -101,10 +110,23 @@ public class TagRepositoryImpl extends AbstractRepository implements TagReposito ...@@ -101,10 +110,23 @@ public class TagRepositoryImpl extends AbstractRepository implements TagReposito
/** /**
* Sets tag article repository with the specified tag article repository. * Sets tag article repository with the specified tag article repository.
* *
* @param tagArticleRepository the specified tag article repository * @param tagArticleRepository the specified tag article repository
*/ */
public void setTagArticleRepository(final TagArticleRepository tagArticleRepository) { public void setTagArticleRepository(final TagArticleRepository tagArticleRepository) {
this.tagArticleRepository = tagArticleRepository; this.tagArticleRepository = tagArticleRepository;
} }
private void sortJSONTagList(List<JSONObject> tagJoList) {
Collections.sort(tagJoList, new Comparator<JSONObject>() {
@Override
public int compare(JSONObject o1, JSONObject o2) {
try {
return CHINA_COMPARE.compare(o1.getString("tagTitle"), o2.getString("tagTitle"));
} catch (JSONException e) {
throw new RuntimeException(e);
}
}
});
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment