Search code examples
javascripttin-can-api

Search TinCan Verbs


Is it possible to filter/search for verbs containing some text in the ID using TinCan?

I.e. below I want to find all verbs that start with a particular ID in the URL?

Or do I have to download all of them and filter?

lrs.queryStatements(
        {
            params: {
                verb: new TinCan.Verb(
                    {
                        id: "http://example.com/g*"
                    }
                ),
                since: "2016-01-05T08:34:16Z"
            },
            callback: function (err, sr) {
                if (err !== null) {
                    console.log("Failed to query statements: " + err);
                    // TODO: do something with error, didn't get statements
                    return;
                }

                if (sr.more !== null) {
                    // TODO: additional page(s) of statements should be fetched
                }
                console.log('query complete');
                console.log(sr);
                // TODO: do something with statements in sr.statements
            }
        }
    );

Solution

  • It isn't possible from the LRS' /statements resource. That resource was never intended as a full query interface and the LRS isn't intended to be searched for direct reporting purposes. It should be thought of more as a stream of data with limited filter capabilities to allow the stream to be manageable for specific long term use cases. So you can "filter" the stream on a specific single identifier, but you can't "search" the statements.