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

design_search with start_key and end_key returns all documents, and does not honor the key range #62

Closed
ghost opened this issue Nov 29, 2017 · 6 comments
Milestone

Comments

@ghost
Copy link

ghost commented Nov 29, 2017

Here is the version of sofa I am using:

packageVersion('sofa')
[1] ‘0.2.2.9214’

Here is what I am trying, based on the view having a composite key on an ID value and a timestamp value:

output <- design_search(
  connection,
  'dbname',
  design = 'designname',
  view = 'viewname',
  start_key = list("27ea7008aaf5f9bee3b4efd856241f2d", 1506837600),
  end_key = list("27ea7008aaf5f9bee3b4efd856241f2d", 1509515999)
  )

Here is the result where the keys returned are completely out of range with the first key value having 17 unique values whereas I only specified exactly one, and the second value of the key being totally out of range where as I specified a range above:

length(unique((sapply(output$rows, function(x) x$key[[1]]))))
[1] 17
summary((sapply(output$rows, function(x) x$key[[2]])))
     Min.   1st Qu.    Median      Mean   3rd Qu.      Max. 
1.475e+09 1.495e+09 1.503e+09 1.501e+09 1.510e+09 1.512e+09 

Is there a different way to specify this correctly that I am missing? I also tried as follows with a vector instead of list and the output has no change:

output <- design_search(
  connection,
  'dbname',
  design = 'designname',
  view = 'viewname',
  start_key = c("27ea7008aaf5f9bee3b4efd856241f2d", 1506837600),
  end_key = c("27ea7008aaf5f9bee3b4efd856241f2d", 1509515999)
  )

When I inspect the documents returned, the key is correctly there as a 'list' with two items, the first being an id and the second being a timestamp:

output[[1]]$key
[[1]]
[1] "09f3eef7b47164b0ed9f1b7775f3e5be"

[[2]]
[1] 1511170394
@sckott sckott added this to the v0.3 milestone Nov 29, 2017
@sckott
Copy link
Contributor

sckott commented Nov 29, 2017

thanks @tumulurig3

can you elaborate on what you mean by composite key?

@ghost
Copy link
Author

ghost commented Nov 29, 2017

Meaning the key is made up of two different fields in the document. Some field called 'some_id' that is a document ID of some other document, and a timestamp field that is integer in seconds since epoch. Both are combined to be the key on the view.

@sckott
Copy link
Contributor

sckott commented Nov 29, 2017

apologies, but i'm not familiar with composite/complex keys. any couchdb docs on that?

@ghost
Copy link
Author

ghost commented Nov 29, 2017

Here is the cloudant screenshot with one of the documents as example. You see id, key and value columns. Value is the actual document. Key is a combination of 'building_id' and 'timestamp' fields. The id is the cloudant ID of the document that is indexed based on building_id/timestamp combination.

Ignore my terminology about 'composite.' All I mean is that the index on this view is made up of two fields within the document.

picture1

@sckott
Copy link
Contributor

sckott commented Nov 29, 2017

thanks for that.

@sckott sckott modified the milestones: v0.3, v0.5 Jan 3, 2018
@sckott sckott modified the milestones: v0.5, v0.4 Nov 9, 2018
sckott added a commit that referenced this issue Nov 9, 2018
needed to add some additional possible values to pass to params
@sckott
Copy link
Contributor

sckott commented Nov 9, 2018

@ghost sorry for the very long delay.

first, those parameters (startkey, endkey) need to be passed to either params or body. if anything is passed to body, it becomes a POST request, if just params, then it's a GET request.

I needed to tweak the internals a bit, and now you can use startkey and endkey , see eg https://github.com/ropensci/sofa/blob/master/R/design_search.R#L123-L135

however, i still haven't figured out how to make it work for composite keys, maybe you will have luck with that.

@sckott sckott closed this as completed Jun 25, 2020
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

1 participant