Browse Source

排序规则增加默认值

sunyj 9 years ago
parent
commit
3bc71e7676
1 changed files with 31 additions and 10 deletions
  1. 31 10
      search-api-b2b/src/main/java/com/uas/search/b2b/model/Sort.java

+ 31 - 10
search-api-b2b/src/main/java/com/uas/search/b2b/model/Sort.java

@@ -34,7 +34,7 @@ public class Sort {
 	private String field;
 
 	/**
-	 * 排序默认为升序,若为true,则为降序
+	 * 排序默认为升序,若为true,则反转为降序
 	 */
 	private boolean reverse = false;
 
@@ -43,29 +43,41 @@ public class Sort {
 	 */
 	private Type type = Type.STRING;
 
-	public Sort(String field, boolean reverse, Type type) {
+	/**
+	 * 若排序字段的值为空,设置一个默认值
+	 */
+	private Object missingValue;
+
+	public Sort(String field, boolean reverse, Type type, Object missingValue) {
+		super();
 		this.field = field;
 		this.reverse = reverse;
 		this.type = type;
+		this.missingValue = missingValue;
 	}
 
-	public Sort(String field, Type type) {
+	public Sort(String field, boolean reverse, Object missingValue) {
+		super();
 		this.field = field;
-		this.type = type;
+		this.reverse = reverse;
+		this.missingValue = missingValue;
 	}
 
-	public Sort(String field, boolean reverse) {
+	public Sort(String field, Type type, Object missingValue) {
+		super();
 		this.field = field;
-		this.reverse = reverse;
+		this.type = type;
+		this.missingValue = missingValue;
 	}
 
-	public Sort() {
+	public Sort(String field, Object missingValue) {
 		super();
+		this.field = field;
+		this.missingValue = missingValue;
 	}
 
-	public Sort(String field) {
+	public Sort() {
 		super();
-		this.field = field;
 	}
 
 	public String getField() {
@@ -92,9 +104,18 @@ public class Sort {
 		this.type = type;
 	}
 
+	public Object getMissingValue() {
+		return missingValue;
+	}
+
+	public void setMissingValue(Object missingValue) {
+		this.missingValue = missingValue;
+	}
+
 	@Override
 	public String toString() {
-		return "Sort [field=" + field + ", reverse=" + reverse + ", type=" + type + "]";
+		return "Sort [field=" + field + ", reverse=" + reverse + ", type=" + type + ", missingValue=" + missingValue
+				+ "]";
 	}
 
 }