bg
Nested Index – BangDB = NoSQL + AI + Stream

Nested Index

chevron

Nested Index

Like in previous section, taking the same document, now let's say we wish to index city as well so that we could search people using city. To do this we will create the nested index like this;

tbl->addIndex("address.city", 40, true);
And now we can search using the scan_doc again for both name and city like following; Note than joinop is 0 which means AND, see the join_operator enum in the enum section.
Therefore, the query looks like following;
scan the table where name is sachin and city is bangalore
const char *query = {"query":[{"key":"name", "cmp_op":4, "val":"sachin"},{"joinop":0},{"key":"address.city", "cmp_op":4, "val":"Bangalore"}]};

resultset *rs = NULL;
scan_filter sf;
while(true)
{
    rs = tbl->scan_doc(rs, NULL, NULL, query, &sf);
    if(!rs)
        break;
    while(rs->hasNext())
    {
        // keys and vals
        rs->moveNext();
    }
}