This commit is contained in:
kimchy 2010-08-09 09:06:14 +03:00
parent 6611e7db44
commit f10699d5b8
5 changed files with 54 additions and 0 deletions

View File

@ -24,6 +24,8 @@ import org.elasticsearch.common.xcontent.builder.XContentBuilder;
import java.io.IOException; import java.io.IOException;
/** /**
* A sort builder to sort based on a document field.
*
* @author kimchy (shay.banon) * @author kimchy (shay.banon)
*/ */
public class FieldSortBuilder extends SortBuilder { public class FieldSortBuilder extends SortBuilder {
@ -32,10 +34,18 @@ public class FieldSortBuilder extends SortBuilder {
private SortOrder order; private SortOrder order;
/**
* Constructs a new sort based on a document field.
*
* @param fieldName The field name.
*/
public FieldSortBuilder(String fieldName) { public FieldSortBuilder(String fieldName) {
this.fieldName = fieldName; this.fieldName = fieldName;
} }
/**
* The order of sorting. Defaults to {@link SortOrder#ASC}.
*/
public FieldSortBuilder order(SortOrder order) { public FieldSortBuilder order(SortOrder order) {
this.order = order; this.order = order;
return this; return this;

View File

@ -26,6 +26,8 @@ import org.elasticsearch.common.xcontent.builder.XContentBuilder;
import java.io.IOException; import java.io.IOException;
/** /**
* A geo distance based sorting on a geo point like field.
*
* @author kimchy (shay.banon) * @author kimchy (shay.banon)
*/ */
public class GeoDistanceSortBuilder extends SortBuilder { public class GeoDistanceSortBuilder extends SortBuilder {
@ -40,6 +42,11 @@ public class GeoDistanceSortBuilder extends SortBuilder {
private DistanceUnit unit; private DistanceUnit unit;
private SortOrder order; private SortOrder order;
/**
* Constructs a new distance based sort on a geo point like field.
*
* @param fieldName The geo point like field name.
*/
public GeoDistanceSortBuilder(String fieldName) { public GeoDistanceSortBuilder(String fieldName) {
this.fieldName = fieldName; this.fieldName = fieldName;
} }
@ -80,6 +87,9 @@ public class GeoDistanceSortBuilder extends SortBuilder {
return this; return this;
} }
/**
* The order of sorting. Defaults to {@link SortOrder#ASC}.
*/
public GeoDistanceSortBuilder order(SortOrder order) { public GeoDistanceSortBuilder order(SortOrder order) {
this.order = order; this.order = order;
return this; return this;

View File

@ -24,12 +24,17 @@ import org.elasticsearch.common.xcontent.builder.XContentBuilder;
import java.io.IOException; import java.io.IOException;
/** /**
* A sort builder allowing to sort by score.
*
* @author kimchy (shay.banon) * @author kimchy (shay.banon)
*/ */
public class ScoreSortBuilder extends SortBuilder { public class ScoreSortBuilder extends SortBuilder {
private SortOrder order; private SortOrder order;
/**
* The order of sort scoring. By default, its {@link SortOrder#DESC}.
*/
public ScoreSortBuilder order(SortOrder order) { public ScoreSortBuilder order(SortOrder order) {
this.order = order; this.order = order;
return this; return this;

View File

@ -20,22 +20,43 @@
package org.elasticsearch.search.sort; package org.elasticsearch.search.sort;
/** /**
* A set of static factory methods for {@link SortBuilder}s.
*
* @author kimchy (shay.banon) * @author kimchy (shay.banon)
*/ */
public class SortBuilders { public class SortBuilders {
/**
* Constructs a new score sort.
*/
public static ScoreSortBuilder scoreSort() { public static ScoreSortBuilder scoreSort() {
return new ScoreSortBuilder(); return new ScoreSortBuilder();
} }
/**
* Constructs a new field based sort.
*
* @param field The field name.
*/
public static FieldSortBuilder fieldSort(String field) { public static FieldSortBuilder fieldSort(String field) {
return new FieldSortBuilder(field); return new FieldSortBuilder(field);
} }
/**
* Constructs a new script based sort.
*
* @param script The script to use.
* @param type The type, can either be "string" or "number".
*/
public static ScriptSortBuilder scriptSort(String script, String type) { public static ScriptSortBuilder scriptSort(String script, String type) {
return new ScriptSortBuilder(script, type); return new ScriptSortBuilder(script, type);
} }
/**
* A geo distance based sort.
*
* @param fieldName The geo point like field name.
*/
public static GeoDistanceSortBuilder geoDistanceSort(String fieldName) { public static GeoDistanceSortBuilder geoDistanceSort(String fieldName) {
return new GeoDistanceSortBuilder(fieldName); return new GeoDistanceSortBuilder(fieldName);
} }

View File

@ -20,9 +20,17 @@
package org.elasticsearch.search.sort; package org.elasticsearch.search.sort;
/** /**
* A sorting order.
*
* @author kimchy (shay.banon) * @author kimchy (shay.banon)
*/ */
public enum SortOrder { public enum SortOrder {
/**
* Ascending order.
*/
ASC, ASC,
/**
* Descending order.
*/
DESC DESC
} }