Add field factory for scope/ordering
341778
def add_field_factory(name, type, options = {}, &block)
      stored, more_like_this = options[:stored], options[:more_like_this]
      field_factory = FieldFactory::Static.new(name, type, options, &block)
      @field_factories[field_factory.signature] = field_factory
      @field_factories_cache[field_factory.name] = field_factory
      if stored
        @stored_field_factories_cache[field_factory.name] << field_factory
      end
      if more_like_this
        @more_like_this_field_factories_cache[field_factory.name] << field_factory
      end
    end
1365702
public static LocalProperties forOrdering(Ordering o) {
		LocalProperties props = new LocalProperties();
		props.ordering = o;
		props.groupedFields = o.getInvolvedIndexes();
		return props;
	}
1289059
public void addOrderBy(String fieldName, boolean sortAscending)
    {
        if (fieldName != null)
        {
            m_orderby.add(new FieldHelper(fieldName, sortAscending));
        }
    }
1093678
def order_by(self, field_name=None):
        
        assert self.query.can_filter(), "Cannot reorder a query once a slice has been taken."

        clone = self._clone()
        clone.query.clear_ordering()

        if field_name is not None:
            clone.query.add_ordering(field_name)

        return clone
137785
def order_by(self, *field_names):
        
        obj = self._clone()
        obj._clear_ordering()
        for field in field_names:
            if field.startswith("-"):
                obj._ordering.append({ field.lstrip("-").replace("__", ".") : "desc" })
            else:
                obj._ordering.append({ field : "asc" })
        return obj
453160
def configure_scope(self, callback=None):  # noqa
        """"""

        client, scope = self._stack[-1]
        if callback is not None:
            if client is not None:
                callback(scope)

            return None

        @contextmanager
        def inner():
            if client is not None:
                yield scope
            else:
                yield Scope()

        return inner()
1010768
def apply_ordering_to_scope(scope, user_params)
      sort_name, direction = calculate_sort_name_and_direction(user_params)
      order = configuration[:sort_orders].fetch(sort_name, {})[:value]

      ordered_scope = case order
        when Proc
          fresh_helper_instance.instance_exec(scope, direction, &order)
        when nil
          scope
        else
          scope.reorder(order.to_s + " " + direction)
      end

      fallback_deterministic_sort = assemble_primary_key_sort(scope)
      # Chain on a tiebreaker sort to ensure deterministic ordering of multiple pages of data

      if fallback_deterministic_sort
        ordered_scope.order(fallback_deterministic_sort)
      else
        ordered_scope
      end
    end
737849
def provider_factory(factory=_sentinel, scope=NoneScope):
    '''
    
    '''
    if factory is _sentinel:
        return functools.partial(provider_factory, scope=scope)
    provider = Provider(factory, scope)
    return provider
563198
def _create_relational_field(self, attr, options):
        """"""
        options['entity_class'] = attr.py_type
        options['allow_empty'] = not attr.is_required
        return EntityField, options
202645
def fields_for(*args, &block)
      if search_obj = args.find { |arg| arg.is_a?(Searchlogic::Search) }
        args.unshift(:search) if args.first == search_obj
        options = args.extract_options!
        if !options[:skip_order_field]
          concat(content_tag("div", hidden_field_tag("#{args.first}[order]", search_obj.order), :style => "display: inline"))
        end
        args << options
        super
      else
        super
      end
    end
821156
function( json, field, params, callback ){
    field = field || 'id';
    var objectIds = [],
      props;

    if (params.orderByFields && params.orderByFields !== ''){
      var fld = params.orderByFields.split(' ');
      var order = params.orderByFields;
      if (fld[fld.length-1] == 'DESC'){
        order = '-' + params.orderByFields;
      }
      json.features = this.orderBy(json.features, params.orderByFields, order);
    }

    json.features.forEach( function(f){
      props = f.attributes || f.properties;
      objectIds.push( props[ field ] );
    });

    callback( null, {
      objectIdField: field,
      objectIds: objectIds
    });
  }
323396
private AbstractAggregationBuilder makeTopHitsAgg(MethodField field) {
        String alias = gettAggNameFromParamsOrAlias(field);
        TopHitsAggregationBuilder topHits = AggregationBuilders.topHits(alias);
        List<KVValue> params = field.getParams();
        String[] include = null;
        String[] exclude = null;
        for (KVValue kv : params) {
            switch (kv.key) {
                case "from":
                    topHits.from((int) kv.value);
                    break;
                case "size":
                    topHits.size((int) kv.value);
                    break;
                case "include":
                    include = kv.value.toString().split(",");
                    break;
                case "exclude":
                    exclude = kv.value.toString().split(",");
                    break;
                case "alias":
                case "nested":
                case "reverse_nested":
                case "children":
                    break;
                default:
                    topHits.sort(kv.key, SortOrder.valueOf(kv.value.toString().toUpperCase()));
                    break;
            }
        }
        if (include != null || exclude != null) {
            topHits.fetchSource(include, exclude);
        }
        return topHits;
    }
337030
function parseOrders(field, fieldName, model) {
		var orders = field.order;
		if (!orders) return;
		if (!Array.isArray(orders)) orders = field.order = [orders];

		_.forEach(orders, function(order, index) {
			// if just a string, leave alone - is raw query
			if (_.isString(order)) return;

			// if an object (e.g. {raw: ...}), add 'ASC' sort order
			if (!Array.isArray(order)) {
				orders[index] = [order, 'ASC'];
				return;
			}

			// add 'ASC' sort order if no sort order defined
			if (order.length == 0) throw new Sequelize.VirtualFieldsError("Invalid virtual field order in '" + model.name + "'.'" + fieldName + "'");
			if (order.length == 1) {
				order[1] = 'ASC';
			} else {
				// ensure direction is ASC or DESC
				if (['ASC', 'DESC'].indexOf(order[order.length - 1].toUpperCase()) == -1) {
					order.push('ASC');
				} else {
					order[order.length - 1] = order[order.length - 1].toUpperCase();
				}
			}

			// make preceeding models into {model: model} form
			var parent = model;
			for (var i = 0; i < order.length - 2; i++) {
				parseClause(order, i, 'Order', model.name, fieldName, parent);
				parent = order[i].model;
			}

			// check attribute is valid
			var attribute = order[order.length - 2];
			if (_.isString(attribute) && !parent.attributes[attribute]) throw new Sequelize.VirtualFieldsError("Order of virtual field '" + model.name + "'.'" + fieldName + "' refers to a nonexistent field '" + parent.name + "'.'" + attribute + "'");
		});
	}
471560
function (instance, sourceFields) {
        var slugParts = sourceFields.map(function (slugSourceField) {
            return instance[slugSourceField];
        });

        var options = (slugOptions && slugOptions.slugOptions) || { lower: true};
        return slug(slugParts.join(' '), options);
    }
1321336
function addPluginsToScope(scope) {
    var name;
    for (name in plugins) {
        if (plugins.hasOwnProperty(name)) {
            scope[name] = plugins[name];
        }
    }
}
909552
def make_scope(self, col_scope_list=None, row_scope_list=None):
        """"""
        if col_scope_list is not None and len(col_scope_list) > 0:
            self.apply_scope(col_scope_list, "col")

        if row_scope_list is not None and len(row_scope_list) > 0:
            self.apply_scope(row_scope_list, "row")
495598
def create_order_objects(model, order_fields):
    
    for rel in model._meta.get_all_related_objects():
        rel_model = rel.model
        if rel_model.__module__ == 'order.models':

            objs = model.objects.all()
            values = {}
            for order_field in order_fields:
                order_objs = rel_model.objects.all().order_by('-%s' \
                        % order_field)
                try:
                    values[order_field] = getattr(order_objs[0], \
                            order_field) + 1
                except IndexError:
                    values[order_field] = 1
            for obj in objs:
                try:
                    rel_model.objects.get(item=obj)
                except rel_model.DoesNotExist:
                    rel_model.objects.create(item=obj, **values)
                    for key in values:
                        values[key] += 1