use of com.yelp.nrtsearch.server.luceneserver.field.properties.Sortable in project nrtsearch by Yelp.
the class SortParser method parseSort.
/**
* Decodes a list of request {@link SortType} into the corresponding {@link Sort}.
*
* @param fields list of {@link SortType} from grpc request
* @param sortFieldNames mutable list which will have all sort field names added in sort order,
* may be null
* @param queryFields collection of all possible fields which may be used to sort
*/
public static Sort parseSort(List<SortType> fields, List<String> sortFieldNames, Map<String, FieldDef> queryFields) throws SearchHandler.SearchHandlerException {
List<SortField> sortFields = new ArrayList<>();
for (SortType sub : fields) {
String fieldName = sub.getFieldName();
SortField sf;
if (sortFieldNames != null) {
sortFieldNames.add(fieldName);
}
if (fieldName.equals(DOCID)) {
if (!sub.getReverse()) {
sf = SortField.FIELD_DOC;
} else {
sf = new SortField(null, SortField.Type.DOC, true);
}
} else if (fieldName.equals(SCORE)) {
if (!sub.getReverse()) {
sf = SortField.FIELD_SCORE;
} else {
sf = new SortField(null, SortField.Type.SCORE, true);
}
} else {
FieldDef fd = queryFields.get(fieldName);
if (fd == null) {
throw new SearchHandler.SearchHandlerException(String.format("field: %s was not registered and was not specified as a virtualField", fieldName));
}
if (!(fd instanceof Sortable)) {
throw new IllegalArgumentException(String.format("field: %s does not support sorting", fieldName));
}
sf = ((Sortable) fd).getSortField(sub);
}
sortFields.add(sf);
}
return new Sort(sortFields.toArray(new SortField[0]));
}
use of com.yelp.nrtsearch.server.luceneserver.field.properties.Sortable in project nrtsearch by Yelp.
the class SettingsHandler method parseSort.
/**
* Decodes a list of SortType into the corresponding Sort.
*/
static Sort parseSort(IndexState state, List<SortType> fields, List<String> sortFieldNames, Map<String, FieldDef> dynamicFields) throws SettingsHandlerException {
List<SortField> sortFields = new ArrayList<>();
for (SortType _sub : fields) {
String fieldName = _sub.getFieldName();
SortField sf;
if (sortFieldNames != null) {
sortFieldNames.add(fieldName);
}
if (fieldName.equals("docid")) {
sf = SortField.FIELD_DOC;
} else if (fieldName.equals("score")) {
sf = SortField.FIELD_SCORE;
} else {
FieldDef fd;
if (dynamicFields != null) {
fd = dynamicFields.get(fieldName);
} else {
fd = null;
}
if (fd == null) {
fd = state.getField(fieldName);
}
if (fd == null) {
throw new SettingsHandlerException("field \"" + fieldName + "\" was not registered and was not specified as a dynamicField");
}
if (!(fd instanceof Sortable)) {
throw new SettingsHandlerException(String.format("field: %s does not support sorting", fieldName));
}
sf = ((Sortable) fd).getSortField(_sub);
}
sortFields.add(sf);
}
return new Sort(sortFields.toArray(new SortField[0]));
}
Aggregations