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

Search and Navigator do not return all results #127

Open
Wu-Li opened this issue Jul 2, 2015 · 5 comments
Open

Search and Navigator do not return all results #127

Wu-Li opened this issue Jul 2, 2015 · 5 comments

Comments

@Wu-Li
Copy link

Wu-Li commented Jul 2, 2015

Hello. I've been building a database to store file metadata, and I've noticed that my search results are not returning many of the matching objects.

For example, my database uses a "folder" type node to group objects so I can query smaller sections of the graph. Like so:

{ subject: 'red fish', predicate: 'contains', object: 'salmon' },
{ subject: 'salmon', predicate: 'tastes', object: 'yummy' },
{ subject: 'red fish', predicate: 'contains', object: 'tuna' },
{ subject: 'blue fish', predicate: 'contains', object: 'trout' },
{ subject: 'blue fish', predicate: 'contains', object: 'halibut' }

If I perform a search, or begin the navigator at 'red fish' it will correctly return the triples linking to all of the types of red fish. However, if I try to step further out using the navigator, or use more than 1 variable in the second object of a search, many of the results do not turn up. For example
db.nav('red fish').archOut('contains') ##This returns all of the red fish
db.nav.('red fish').archOut('contains').archOut(db.v('anything'))
^Shows some of the nodes linked to red fish, but is missing most of them^

A similarly structured search also omits many results:

db.search([{
  subject: 'red fish'
  predicate: 'contains'
  object: db.v('fishes')
},{
  subject: db.v('fishes')
  predicate: db.v('y')
  object: db.v('z')
}]

If this isn't a bug, am I doing something completely wrong here? All I've been trying to do is get all of the nodes two links away from a specific node, regardless of the predicate or object, and it doesn't seem like there is any way to do this.

@doowb
Copy link
Collaborator

doowb commented Jul 2, 2015

I think this is related to #116. Have you tried setting { joinAlgorithm: 'basic' }. This will probably slow down the search, but it should return the correct results.

@Wu-Li
Copy link
Author

Wu-Li commented Jul 17, 2015

I did try using joinAlgorithm: 'basic', and I got the same results. I'm not completely sure I'm using the Navigator correctly. I do seem to be getting better results using a searchStream though.

@mcollina
Copy link
Collaborator

Probably you are not using the navigator correctly, but it is perfectly use just searchStream. Navigator is built on top of searchStream.

@Wu-Li
Copy link
Author

Wu-Li commented Jul 21, 2015

I can confirm that this is occurring for both search and search stream as well, and for both sort and basic join algorithms. I've narrowed down the conditions under which it omits results.

Always correct:

  • Searches with 1 triple
  • Searches with only 0 or 1 search string per triple

Omits results:

  • Searches with more than 1 triple and 2 search strings in any triple

For example:

{
  subject: db.v('x')
  predicate: 'hasColor'
  object: 'blue'
}
returns 100 records of blue fish

{
  subject: db.v('x')
  object: 'blue'
},{
  subject: db.v('x')
}
also returns 100 records of blue fish

{
  subject: db.v('x')
  predicate: 'hasColor'
  object: 'blue'
},{
  subject: db.v('x')
}
returns 33 records of blue fish

Adding more db variables doesn't change the result count, just which values are returned.

I would be happy to help fix this, though I'm not really sure where to start. If someone could point me in the right direction, I'll submit a PR and do some troubleshooting.

@mcollina
Copy link
Collaborator

The search is supped to be used with the full pattern specified. Does that change anything?
The 'basic' joinAlgorithm should definitely work, as it's basically rerunning all the various steps for any possible results.

Anyway, the first step to address this issue is writing a unit test that cover this case. Add one to: https://github.com/mcollina/levelgraph/blob/master/test/abstract_join_algorithm.js

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