Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

filterTwoArguments not working #104

Open
neonstalwart opened this issue Dec 12, 2014 · 4 comments
Open

filterTwoArguments not working #104

neonstalwart opened this issue Dec 12, 2014 · 4 comments

Comments

@neonstalwart
Copy link
Collaborator

it looks like filterTwoArguments doesn't work.

db.search([
    {
        subject: user,
        predicate: 'like',
        object: db.v('liked')
    },
    {
        subject: db.v('someone'),
        predicate: 'like',
        object: db.v('liked'),
        filter: function (triple, cb) {
            cb(null, triple);
        }
    }
])

what i'm trying to do is to filter out all the things already liked by user. i realize that i can do this with a filter on the results but i was thinking that maybe it's better for performance to filter on the query rather than the results but i'm open to hearing that it's not.

@neonstalwart
Copy link
Collaborator Author

i think this is broken for filtering results too. i'll try to confirm tomorrow and hopefully produce a test case and fix.

@mcollina
Copy link
Collaborator

Thanks, I have no bandwidth for LG at the moment :/.

@neonstalwart
Copy link
Collaborator Author

i seem to have found more issues while trying to write tests for this one. maybe my mental model is wrong so i'm not going to try to fix anything until i hear from you about #105 and in particular #105 (comment)

@jbuck167
Copy link

jbuck167 commented Mar 25, 2019

Update: I looked at filterTwoArguments and it was not the cause of the problem I found. I was able to repeat the issue with filterOneArgument. I have found a problem with the joinstream that is due to control flow of the various streams involved in a search. Please see #186


Hello! I am here because I replicated the problem originally posted. To summarize the problem, there is an issue when doing searches with an array of triples where there is a filter function in one or more of the triples in the array other than the first triple.

Example problematic search:
db.search([triple1, triple2, ..., tripleN])

where at least one of the triples other than triple1 has a filter like the following:

triple2 = {
   subject: db.v(var1)
   filter: function(triple) {
      return true;      
   }
}

I tried several combinations of using filters inside of search triples. I found that putting a filter in a search triple other than the first triple in the array caused the search to never resolve. The search will work if there is a filter in the first triple of the array only:

This worked for me:

db.search([
    {
        subject: db.v('someone'),
        predicate: 'like',
        object: db.v('liked'),
        filter: function (triple, cb) {
            cb(null, triple);
        }
    },
    {
        subject: user,
        predicate: 'like',
        object: db.v('liked')
    }
])

I was able to replicate this with many examples. As long as there were no filters after the first triple, I got results. If there was a filter in any triple other than the first, the search never resolves. I also tested filtering full solutions and there were no problems there. Also interesting: the filters at the triple scope are always executed, and the full solution filter is also executed. Despite this, the search still does not resolve if there was a filter in any but the first triple in the search.

Working Example:

db.search([
    {
        subject: db.v('someone'),
        predicate: 'like',
        object: db.v('liked'),
        filter: function (triple, cb) {
            cb(null, triple);
        }
    },
    {
        subject: user,
        predicate: 'like',
        object: db.v('liked')
    }
], { 
   filter: function(solution, callback) {
      callback(null, solution);
   }
})

Broken Example:

db.search([
    {
        subject: user,
        predicate: 'like',
        object: db.v('liked')
    },
    {
        subject: db.v('someone'),
        predicate: 'like',
        object: db.v('liked'),
        filter: function (triple, cb) {
            cb(null, triple);
        }
    }
], { 
   filter: function(solution, callback) {
      callback(null, solution);
   }
})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants