Implement search #61
3 changed files with 36 additions and 11 deletions
|
@ -17,15 +17,28 @@ impl<'a> Index<'a> {
|
|||
.iter()
|
||||
.enumerate()
|
||||
.map(|(i_enum, (&uid, &uuid))| {
|
||||
let flags = internal.table.get(&uuid).ok_or(anyhow!("mail is missing from index"))?.1.as_ref();
|
||||
let flags = internal
|
||||
.table
|
||||
.get(&uuid)
|
||||
.ok_or(anyhow!("mail is missing from index"))?
|
||||
.1
|
||||
.as_ref();
|
||||
let i_int: u32 = (i_enum + 1).try_into()?;
|
||||
let i: NonZeroU32 = i_int.try_into()?;
|
||||
|
||||
Ok(MailIndex { i, uid, uuid, flags })
|
||||
Ok(MailIndex {
|
||||
i,
|
||||
uid,
|
||||
uuid,
|
||||
flags,
|
||||
})
|
||||
})
|
||||
.collect::<Result<Vec<_>>>()?;
|
||||
|
||||
Ok(Self { imap_index, internal })
|
||||
Ok(Self {
|
||||
imap_index,
|
||||
internal,
|
||||
})
|
||||
}
|
||||
|
||||
pub fn last(&'a self) -> Option<&'a MailIndex<'a>> {
|
||||
|
@ -62,10 +75,15 @@ impl<'a> Index<'a> {
|
|||
// Quickly jump to the right point in the mailbox vector O(log m) instead
|
||||
// of iterating one by one O(m). Works only because both unroll_seq & imap_index are sorted per uid.
|
||||
let mut imap_idx = {
|
||||
let start_idx = self.imap_index.partition_point(|mail_idx| &mail_idx.uid < start_seq);
|
||||
let start_idx = self
|
||||
.imap_index
|
||||
.partition_point(|mail_idx| &mail_idx.uid < start_seq);
|
||||
&self.imap_index[start_idx..]
|
||||
};
|
||||
println!("win: {:?}", imap_idx.iter().map(|midx| midx.uid).collect::<Vec<_>>());
|
||||
println!(
|
||||
"win: {:?}",
|
||||
imap_idx.iter().map(|midx| midx.uid).collect::<Vec<_>>()
|
||||
);
|
||||
|
||||
let mut acc = vec![];
|
||||
for wanted_uid in unroll_seq.iter() {
|
||||
|
@ -91,7 +109,11 @@ impl<'a> Index<'a> {
|
|||
};
|
||||
sequence_set
|
||||
.iter(iter_strat)
|
||||
.map(|wanted_id| self.imap_index.get((wanted_id.get() as usize) - 1).ok_or(anyhow!("Mail not found")))
|
||||
.map(|wanted_id| {
|
||||
self.imap_index
|
||||
.get((wanted_id.get() as usize) - 1)
|
||||
.ok_or(anyhow!("Mail not found"))
|
||||
})
|
||||
.collect::<Result<Vec<_>>>()
|
||||
}
|
||||
|
||||
|
|
|
@ -32,7 +32,10 @@ pub struct MailView<'a> {
|
|||
}
|
||||
|
||||
impl<'a> MailView<'a> {
|
||||
pub fn new(query_result: &'a QueryResult<'a>, in_idx: &'a MailIndex<'a>) -> Result<MailView<'a>> {
|
||||
pub fn new(
|
||||
query_result: &'a QueryResult<'a>,
|
||||
in_idx: &'a MailIndex<'a>,
|
||||
) -> Result<MailView<'a>> {
|
||||
Ok(Self {
|
||||
in_idx,
|
||||
query_result,
|
||||
|
|
|
@ -526,7 +526,7 @@ mod tests {
|
|||
content: rfc822.to_vec(),
|
||||
};
|
||||
|
||||
let mv = MailView::new(&qr, mail_in_idx)?;
|
||||
let mv = MailView::new(&qr, &mail_in_idx)?;
|
||||
let (res_body, _seen) = mv.filter(&ap)?;
|
||||
|
||||
let fattr = match res_body {
|
||||
|
|
Loading…
Reference in a new issue