Index predicate

Can I specify predicate in order to govern an index inclusion?
Ex: i have rows with firstname, lastname, gender, bodytemperature fields.
I want an index with gender and temperature terms, pre-filtering off
males with no fever.
Is this possible?

Hi @Andrea_Scotti,

Let’s suppose you have a collection like this:

Map(Paginate(Documents(Collection('fever'))),Lambda('x',Get(Var('x'))))
{ data:
   [ { ref: Ref(Collection("fever"), "288976165374263809"),
       ts: 1611847997040000,
       data:
        { firstname: 'name1',
          lastname: 'lastname1',
          gender: 'M',
          bodytemperature: 39 } },
     { ref: Ref(Collection("fever"), "288976178990023175"),
       ts: 1611848010035000,
       data:
        { firstname: 'name2',
          lastname: 'lastname2',
          gender: 'M',
          bodytemperature: 36 } },
     { ref: Ref(Collection("fever"), "288976191975588357"),
       ts: 1611848022400000,
       data:
        { firstname: 'name3',
          lastname: 'lastname3',
          gender: 'F',
          bodytemperature: 36 } },
     { ref: Ref(Collection("fever"), "288976205154091525"),
       ts: 1611848034980000,
       data:
        { firstname: 'name4',
          lastname: 'lastname4',
          gender: 'F',
          bodytemperature: 40 } } ] }

You can create an index like this:

CreateIndex(
  {
    name:'fever1',
    source:Collection("fever"),
    values:[
      {field:['data','gender']},
      {field:['data','bodytemperature']},
      {field:['data','firstname']},
      {field:['data','lastname']}
    ]
  }
)

And you can query:

  • all female or male with fever
Paginate(Range(Match('fever1'),['F',37],['F',43]))
{ data: [ [ 'F', 40, 'name4', 'lastname4' ] ] }
  • all female or male without fever
Paginate(Range(Match('fever1'),['M',30],['M',36]))
{ data: [ [ 'M', 36, 'name2', 'lastname2' ] ] }
  • all female and male with or without fever
Paginate(Union(Range(Match('fever1'),['F',37],['F',43]),Range(Match('fever1'),['M',37],['M',43])))
{ data:
   [ [ 'F', 40, 'name4', 'lastname4' ],
     [ 'M', 39, 'name1', 'lastname1' ] ] }

Hope this helps!

Luigi

Thanks for your reply.
More specifically, I’d like to put in the index, for example, just females with fever.
I kinda need to attach a lambda to the index in order to say something like: this object goes into it, this one does not…

I think I would use a binding casting the temperature to a bool representing the fever case.