Exemplo n.º 1
0
        /// <summary>
        /// Sort result using specified field.
        /// There can be several Sort parameters (order is important).
        /// </summary>
        /// <param name="field">The field. Use _score to sort by score.</param>
        /// <param name="order">The sort order. By default order depends on chosen field (descending for "_scope", ascending for others) and field analyzer.</param>
        /// <param name="missing">The missing value handling strategy. Use _last, _first or custom value.</param>
        /// <param name="ignoreUnmapped"> The ignore_unmapped option allows to ignore fields that have no mapping and not sort by them. </param>
        public Sort <T> Field(string field, SortDirection order = SortDirection.@default, string missing = null, bool ignoreUnmapped = false)
        {
            var fieldParams = new List <string>();

            if (order != SortDirection.@default)
            {
                fieldParams.Add("'order': {0}".AltQuoteF(order.AsString().Quotate()));
            }

            if (!missing.IsNullOrEmpty())
            {
                fieldParams.Add("'missing': {0}".AltQuoteF(missing.Quotate()));
            }

            if (ignoreUnmapped)
            {
                fieldParams.Add("'ignore_unmapped': true".AltQuote());
            }

            if (fieldParams.Any())
            {
                RegisterJsonPart("{{ {0}: {{ {1} }} }}", field.Quotate(), fieldParams.JoinWithComma());
            }
            else
            {
                RegisterJsonPart(field.Quotate());
            }

            return(this);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Sorting to perform. There can be several Sort parameters (order is important).
        /// Use "_score" to sort by query score.
        /// </summary>
        public SearchCommand Sort(string fieldname, SortDirection direction = SortDirection.@default)
        {
            string value = fieldname;

            if (direction != SortDirection.@default)
            {
                value += ":" + direction.AsString();
            }

            WithParameter("sort", value);
            return(this);
        }
Exemplo n.º 3
0
        private Sort <T> AddGeoDistancePart(string geoField, DistanceUnit unit, SortDirection order = SortDirection.@default)
        {
            var fieldParams = new List <string>();

            fieldParams.Add("'unit': {0}".AltQuoteF(unit.AsString().Quotate()));

            if (order != SortDirection.@default)
            {
                fieldParams.Add("'order': {0}".AltQuoteF(order.AsString().Quotate()));
            }

            fieldParams.Add(geoField);

            RegisterJsonPart("{{ '_geo_distance': {{ {0} }} }}", fieldParams.JoinWithComma());

            return(this);
        }
Exemplo n.º 4
0
        public Sort <T> Script(string script, string type, SortDirection order, string[] @params)
        {
            var expression = "'_script' : {0}, 'type': {1}, 'order': {2}, 'params': {3} ".AltQuoteF(script, type.Quotate(), order.AsString().Quotate(), @params.JoinWithComma());

            RegisterJsonPart(expression);

            return(this);
        }
Exemplo n.º 5
0
        public Sort <T> Script(string script, string type, string @params, SortDirection order)
        {
            var expression = "{{ '_script': {{ 'script': {0},'type': {1},'params': {2},'order': {3} }} }}".AltQuoteF(script.Quotate(), type.Quotate(), @params, order.AsString().Quotate());

            RegisterJsonPart(expression);

            return(this);
        }