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

How to get original document whilst iterating through query results? #9

Open
SaadAttieh opened this issue Nov 29, 2020 · 1 comment

Comments

@SaadAttieh
Copy link

I couldn't see an example of how to do this so I guessed it would just be calling dbase.get on the doc_id in the query result.

//adapted from tags example
    let results = dbase.query_by_key("tags", b"cat").unwrap();
    for result in results {
        let doc_id = str::from_utf8(&result.doc_id).unwrap().to_owned();
        println!("query result key: {:}", doc_id);
        println!("tag value: {}", str::from_utf8(&result.value).unwrap().to_owned());
        println!("get actual value  {:?}", dbase.get::<Asset,_>(result.doc_id).ok().unwrap());
    }

But I get the mutable borrow error:

error[E0502]: cannot borrow `dbase` as immutable because it is also borrowed as mutable
   --> src/main.rs:123:44
    |
118 |     let results = dbase.query_by_key("tags", b"cat").unwrap();
    |                   ----- mutable borrow occurs here
119 |     for result in results {
    |                   ------- mutable borrow later used here
...
123 |         println!("get actual value  {:?}", dbase.get::<Asset,_>(result.doc_id).ok().unwrap());
    |                                            ^^^^^ immutable borrow occurs here

@nlfiedler
Copy link
Owner

You are quite right that this use case was not considered when designing the API. For my purposes, I only needed the index values, and querying the full documents would come later as needed. It would require a different kind of iterator that returns the primary value along with the index values.

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

2 participants