Reduce the number of KV lookups to the sucessfulls only

This commit is contained in:
Kerollmops 2020-06-16 12:58:29 +02:00
parent e974e6b3c9
commit 3577de04b8
No known key found for this signature in database
GPG Key ID: 92ADA4E935E71FA4

View File

@ -102,11 +102,11 @@ impl Index {
// TODO re-enable the prefixes system // TODO re-enable the prefixes system
let mut stream = fst.search(&dfa).into_stream(); let mut stream = fst.search(&dfa).into_stream();
while let Some(word) = stream.next() { while let Some(word) = stream.next() {
derived_words.push(word.to_vec());
let word = std::str::from_utf8(word)?; let word = std::str::from_utf8(word)?;
if let Some(attrs) = self.postings_attrs.get(rtxn, word)? { if let Some(attrs) = self.postings_attrs.get(rtxn, word)? {
let right = RoaringBitmap::deserialize_from(attrs)?; let right = RoaringBitmap::deserialize_from(attrs)?;
union_positions.union_with(&right); union_positions.union_with(&right);
derived_words.push((word.as_bytes().to_vec(), right));
count += 1; count += 1;
} }
} }
@ -145,7 +145,8 @@ impl Index {
for (i, (derived_words, pos))in once(left).chain(once(right)).enumerate() { for (i, (derived_words, pos))in once(left).chain(once(right)).enumerate() {
let mut union_docids = RoaringBitmap::default(); let mut union_docids = RoaringBitmap::default();
// TODO re-enable the prefixes system // TODO re-enable the prefixes system
for word in derived_words.iter() { for (word, attrs) in derived_words.iter() {
if attrs.contains(pos) {
if i == 0 { l_lookups += 1 } else { r_lookups += 1 } if i == 0 { l_lookups += 1 } else { r_lookups += 1 }
let mut key = word.clone(); let mut key = word.clone();
key.extend_from_slice(&pos.to_be_bytes()); key.extend_from_slice(&pos.to_be_bytes());
@ -155,6 +156,7 @@ impl Index {
union_docids.union_with(&right); union_docids.union_with(&right);
} }
} }
}
match &mut intersect_docids { match &mut intersect_docids {
Some(left) => left.intersect_with(&union_docids), Some(left) => left.intersect_with(&union_docids),
@ -189,7 +191,8 @@ impl Index {
let before = Instant::now(); let before = Instant::now();
// TODO re-enable the prefixes system // TODO re-enable the prefixes system
for word in derived_words.iter() { for (word, attrs) in derived_words.iter() {
if attrs.contains(pos) {
let mut key = word.clone(); let mut key = word.clone();
key.extend_from_slice(&pos.to_be_bytes()); key.extend_from_slice(&pos.to_be_bytes());
if let Some(attrs) = self.postings_ids.get(rtxn, &key)? { if let Some(attrs) = self.postings_ids.get(rtxn, &key)? {
@ -198,6 +201,7 @@ impl Index {
count += 1; count += 1;
} }
} }
}
let before_intersect = Instant::now(); let before_intersect = Instant::now();