Introduce a method to retrieve the number of attributes of the documents

This commit is contained in:
Kerollmops 2020-07-13 17:50:16 +02:00
parent 54afec58a3
commit 6b14b20369
No known key found for this signature in database
GPG Key ID: 92ADA4E935E71FA4

View File

@ -74,6 +74,17 @@ impl Index {
self.main.get::<_, Str, ByteSlice>(rtxn, "headers") self.main.get::<_, Str, ByteSlice>(rtxn, "headers")
} }
pub fn number_of_attributes<'t>(&self, rtxn: &'t heed::RoTxn) -> anyhow::Result<Option<usize>> {
match self.headers(rtxn)? {
Some(headers) => {
let mut rdr = csv::Reader::from_reader(headers);
let headers = rdr.headers()?;
Ok(Some(headers.len()))
}
None => Ok(None),
}
}
pub fn put_fst<A: AsRef<[u8]>>(&self, wtxn: &mut heed::RwTxn, fst: &fst::Set<A>) -> anyhow::Result<()> { pub fn put_fst<A: AsRef<[u8]>>(&self, wtxn: &mut heed::RwTxn, fst: &fst::Set<A>) -> anyhow::Result<()> {
Ok(self.main.put::<_, Str, ByteSlice>(wtxn, "words-fst", fst.as_fst().as_bytes())?) Ok(self.main.put::<_, Str, ByteSlice>(wtxn, "words-fst", fst.as_fst().as_bytes())?)
} }
@ -146,9 +157,9 @@ impl Index {
} }
let mut words_attributes_docids = Vec::new(); let mut words_attributes_docids = Vec::new();
let number_attributes: u32 = 6; let number_of_attributes = self.number_of_attributes(rtxn)?.map_or(0, |n| n as u32);
for i in 0..number_attributes { for i in 0..number_of_attributes {
let mut intersect_docids: Option<RoaringBitmap> = None; let mut intersect_docids: Option<RoaringBitmap> = None;
for derived_words in &words { for derived_words in &words {
let mut union_docids = RoaringBitmap::new(); let mut union_docids = RoaringBitmap::new();