Range

Not available in this language yet.
Range( set, from, to )
Range( set, from, to )
Range( set, from, to )
Not available in this language yet.
Not available in this language yet.
Range( set, from, to )
Not available in this language yet.

Description

The Range function returns an inclusive subset of the values from the provided set that includes the range of values starting from from up to to, as defined by the order of the set.

Items in a set can be single, scalar values, or can be tuples containing a variety of values of different types. from and to are expressed as prefixes that need to match some, or all, of the structure provided by the set, or Range returns an empty set. For example, if an index’s values field contains last and first fields, from and to can be expressed as just a last name, or an array containing the last and first names to mark the boundary of the range.

Both from and to can be expressed as an empty array, which indicates that the range should extend to, respectively, the set’s first item, or the set’s last item. If both from and to are expressed as an empty arrange, the entire range is returned.

Parameters

Argument Type Definition and Requirements

set

Set

The set

from

Value, or Array of values

The value(s) marking the start of the range to return. from is inclusive.

Use an empty array to indicate that from should start with the first item in the set.

to

Value, or Array of values

The value(s) marking the end of the range to return. to is inclusive.

Use an empty array to indicate that to should end with the last item in the set.

Returns

A new set containing values from set in the range between from and to inclusive.

Examples

With a collection containing the letters of the alphabet, and an index with a values field defined to contain each document’s letter field, the following query returns the range of values from F to M:

Not available in this language yet.
  result, err := client.Query(
    f.Paginate(
      f.Range(
        f.Match(
          f.Index("letters")),
          "F", "M")))
System.out.println(
    client.query(
        Paginate(
            Range(Match(Index("letters")), Value("F"), Value("M"))
        )
    ).get());
client.query(
  q.Paginate(
    q.Range(q.Match(q.Index("letters")), "F", "M")
  )
)
.then(ret => console.log(ret))
Not available in this language yet.
Not available in this language yet.
println(Await.result(
  client.query(
    Paginate(
      Range(Match(Index("letters")), "F", "M")
    )
  ),
  5.seconds
))
Not available in this language yet.
map[data:[F G H I J K L M]]
{data: ["F", "G", "H", "I", "J", "K", "L", "M"]}
{ data: [ 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M' ] }
{data: ["F", "G", "H", "I", "J", "K", "L", "M"]}

With the same setup, the following query returns all of the letters up to, and including, M:

Not available in this language yet.
  result, err := client.Query(
    f.Paginate(
      f.Range(
        f.Match(
          f.Index("letters")),
          f.Arr{}, "M")))
System.out.println(
    client.query(
        Paginate(
            Range(Match(Index("letters")), Arr(), Value("M"))
        )
    ).get());
client.query(
  q.Paginate(
    q.Range(q.Match(q.Index("letters")), [], "M")
  )
)
.then(ret => console.log(ret))
Not available in this language yet.
Not available in this language yet.
println(Await.result(
  client.query(
    Paginate(
      Range(Match(Index("letters")), Arr(), "M")
    )
  ),
  5.seconds
))
Not available in this language yet.
map[data:[A B C D E F G H I J K L M]]
{data: ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M"]}
{ data:
   [ 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M' ] }
{data: ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M"]}

With the same setup, the following query returns F and all of the subsequent letters:

Not available in this language yet.
  result, err := client.Query(
    f.Paginate(
      f.Range(
        f.Match(
          f.Index("letters")),
          "F", f.Arr{})))
System.out.println(
    client.query(
        Paginate(
            Range(Match(Index("letters")), Value("F"), Arr())
        )
    ).get());
client.query(
  q.Paginate(
    q.Range(q.Match(q.Index("letters")), "F", [])
  )
)
.then(ret => console.log(ret))
Not available in this language yet.
Not available in this language yet.
println(Await.result(
  client.query(
    Paginate(
      Range(Match(Index("letters")), "F", Arr())
    )
  ),
  5.seconds
))
Not available in this language yet.
map[data:[F G H I J K L M N O P Q R S T U V W X Y Z]]
{data: ["F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"]}
{ data:
   [ 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P',
     'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z' ] }
{data: ["F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"]}

The schema setup is not documented here. Most of what you need to make this example work is included in the Index tutorials, including the creation of the collection and the creation of the letters documents. You would need to create an appropriate index, which should look like this:

{ ref: Index("letters"),
  ts: 1566580712100000,
  active: true,
  serialized: true,
  name: 'letters',
  source: Collection("Letters"),
  values: [ { field: [ 'data', 'letter' ] } ],
  partitions: 8 }

With a collection containing people, with first and last names, and an index with a values field defined to contain the last and first fields, the following query returns all of the people from Hopper to Minsky:

Not available in this language yet.
  result, err := client.Query(
    f.Paginate(
      f.Range(
        f.Match(
          f.Index("people_by_last_first")),
          "Hopper", "Minksy")))
    System.out.println(
        client.query(
            Paginate(
                Range(
                    Match(Index("people_by_last_first")),
                    Value("Hopper"), Value("Minsky")
                )
            )
        ).get());
client.query(
  q.Paginate(
    q.Range(
      q.Match(q.Index("people_by_last_first")), "Hopper", "Minsky"
    )
  )
)
.then(ret => console.log(ret))
Not available in this language yet.
Not available in this language yet.
println(Await.result(
  client.query(
    Paginate(
      Range(Match(Index("people_by_last_first")), "Hopper", "Minsky")
    )
  ),
  5.seconds
))
Not available in this language yet.
ap[data:[[Hopper Grace] [Lamport Leslie]]]
{data: [["Hopper", "Grace"], ["Lamport", "Leslie"], ["Minsky", "Marvin"]]}
{ data:
   [ [ 'Hopper', 'Grace' ],
     [ 'Lamport', 'Leslie' ],
     [ 'Minsky', 'Marvin' ] ] }
{data: [["Hopper", "Grace"], ["Lamport", "Leslie"], ["Minsky", "Marvin"]]}

See the Index tutorials for the setup of the People collection. You would need to create an appropriate index, which should look like this:

{ ref: Index("people_by_last_first"),
  ts: 1570226020940000,
  active: true,
  serialized: true,
  name: 'people_by_last_first',
  source: Collection("People"),
  values:
   [ { field: [ 'data', 'last' ] },
     { field: [ 'data', 'first' ] } ],
  partitions: 8 }

Was this article helpful?

We're sorry to hear that.
Tell us how we can improve! documentation@fauna.com

Thank you for your feedback!