Search: does `uses:` flag work and `uses:selection` might be an idea?

Hi There,

I was playing around with the idea of having a search limited to a selection of nodes/groups when I thought how hard could it be?.

So I had a look at the source code and discovered the uses:<node-id> flag:

val = extractValue(val,"uses",flags);// uses:<node-id>

Great I thought, then all I need to do is implement uses:selection, which I did somewhat like this:

if (flags.uses && flags.uses.indexOf("selection") >= 0) {
   let seletectedThings = (RED.view.selection() &&
       RED.view.selection().nodes) || [];

   flags.uses = seletectedThings.map( d => d.id )
   seletectedThings.forEach( thng => {
       if ( thng.type == "group" ) {
          RED.group.getNodes(thng,true,false).forEach( d => flags.uses.push(d.id) )
       }
   })

   flags.uses = [ ...new Set(flags.uses) ]
}

But then I discovered that the uses feature doesn't work or at least I couldn't get it working. So I debugged it. Eventually I figured out how the search works and that the uses flags should be used as a filter and not as a keys reduction value. Anyway, a made two other changes and now the feature is available over at Browser-Red.

uses-search2

3 Likes

Could be a PR ?

I would prefer to have confirmation that a) it's something that will be merged b) enough folks actually want this c) if someone else wants to create a PR, go for it - I don't have an issue with someone else taking the code and claiming the kudos.

And also d) I'm pretty sure that I'm misusing the idea of uses:, I assume it has some other meaning since uses:<node-id> makes no sense since the search is limited to that single node!

Btw the reason I implemented this was because I wanted to import Hacker News discussions and then solely search those discussions for keywords.

1 Like