EventRegistry/event-registry-node-js

Cannot restrict articles to sourceGroupUri in QueryEvent

joelhulen opened this issue · 8 comments

We are conducting article searches and event searches using the Node.js SDK. One of the filters we allow users to apply is the news source group (e.g. general/ERtop10). This works just fine when searching articles. We also pass this when searching events. However, when we retrieve the articles for an event, we can't seem to successfully apply the sourceGroupUri filter on those articles.

I've consulted the SDK source code, and sourceGroupUri appears as a valid parameter for the RequestEventArticles class, as seen here: https://github.com/EventRegistry/event-registry-node-js/blob/master/src/queryEvent.ts#L239

Here is a snippet of my source code. Please note that sourceGroupUri is a recent addition:

    let uri = context.bindingData.uri;
    let sourceGroup = undefined;
    if (
      context.bindingData.sourceGroup &&
      context.bindingData.sourceGroup.length > 0
    ) {
      sourceGroup = context.bindingData.sourceGroup;
      context.log('sourceGroupUri: ' + sourceGroup);
    }
    const q = new erBase.QueryEvent(uri);
    q.setRequestedResult(
      new erBase.RequestEventArticles({
        count: 100,
        lang: ['eng'],
        sourceGroupUri: sourceGroup !== undefined ? [sourceGroup] : undefined
      })
    );

The output of context.log(JSON.stringify(q)); is:

{"params":{"action":"getEvent","eventUri":"eng-4524418"},"resultTypeList":[{"resultType":"articles","params":{"articlesPage":1,"articlesCount":100,"articlesLang":["eng"],"articlesSortBy":"cosSim","articlesSortByAsc":false,"articlesArticleBodyLen":200}}]}

Notice that sourceGroupUri is absent.

I've tried passing the sourceGroupUri value as both a string and a string array.

I must be missing something simple. Any suggestions?

Hi,

I tried to reproduce your issue but so far I was unsuccessful. Could you verify that sourceGroup variable in your snippet is defined ? If it's undefined then it won't be included in the params.

Best regards,
Anze

It is defined. The context.log('sourceGroupUri: ' + sourceGroup); line shows the value in the log output.

@UnspokenMallard Could you perhaps share your code you used to reproduce the issue?

I've used the following snippet, which generates query parameters with source group uri.

var erBase = require("eventregistry");
var er = new erBase.EventRegistry();

var eventUri = "eng-4505657";
var requestEventArticles = new erBase.RequestEventArticles({
    count: 100,
    lang: ["eng"],
    sourceGroupUri: ["general/ERtop50"]
});
var q1 = new erBase.QueryEvent(eventUri);
q1.setRequestedResult(requestEventArticles);
console.log(q1.getQueryParams());
er.execQuery(q1).then((response) => {
    console.log(response);
});

While investigating this issue we did notice a minor mishap on our side, we currently do not support your use case on our backend.

So it's considered as a missing feature and will be added before next week.

@joelhulen Issues were resolved on our end. For reference I used the following snippet.

var erBase = require("eventregistry");
var er = new erBase.EventRegistry();

var requestEventArticles = new erBase.RequestEventArticles({
    count: 100,
    lang: ["eng"],
    sourceGroupUri: ["general/ERtop50"]
});
var q1 = new erBase.QueryEvent("eng-4524180");
q1.setRequestedResult(requestEventArticles);
console.log(q1.getQueryParams());
er.execQuery(q1).then((response) => {
    console.log(response);
});

If there are any more problems please let me know.

@UnspokenMallard I've taken your code above and have run tests using both general/ERtop50 and general/ERtop10.

In both cases, I receive the following results (articles removed for brevity):

{
    "articles": {
        "results": [
            .......
        ],
        "totalResults": 2606,
        "page": 1,
        "count": 100,
        "pages": 27
    }
}

The output of console.log(q1.getQueryParams()); does not include the sourceGroupUri setting:

{ action: 'getEvent', eventUri: 'eng-4524180', articlesPage: 1, articlesCount: 100, articlesLang: [ 'eng' ], articlesSortBy: 'cosSim', articlesSortByAsc: false, articlesArticleBodyLen: 200, resultType: 'articles' }

Any ideas why it doesn't seem to be adding the sourceGroupUri parameter? Or perhaps it is but the value is not being honored in the back-end. I've used your exact code.

@joelhulen Which version of NodeJS SDK are you using? This fine grain filtering was introduced with the NodeJS SDK 8.4.0.

That was it. I was using a slightly older version of the SDK. I thought I had updated it. Everything works now :) Thank you!