fix schema & fix tests

This commit is contained in:
qdequele 2020-01-15 18:53:49 +01:00
parent 116a637cfd
commit ae0a11e422
No known key found for this signature in database
GPG Key ID: B3F0A000EBF11745
3 changed files with 22 additions and 6 deletions

View File

@ -145,6 +145,7 @@ mod tests {
use crate::bucket_sort::SimpleMatch; use crate::bucket_sort::SimpleMatch;
use crate::database::Database; use crate::database::Database;
use crate::store::Index; use crate::store::Index;
use meilisearch_schema::Schema;
fn set_from_stream<'f, I, S>(stream: I) -> Set fn set_from_stream<'f, I, S>(stream: I) -> Set
where where
@ -268,18 +269,34 @@ mod tests {
let mut postings_lists = HashMap::new(); let mut postings_lists = HashMap::new();
let mut fields_counts = HashMap::<_, u16>::new(); let mut fields_counts = HashMap::<_, u16>::new();
let mut schema = Schema::default();
for (word, indexes) in iter { for (word, indexes) in iter {
let mut final_indexes = Vec::new();
for index in indexes {
let name = index.attribute.to_string();
schema.get_or_create(&name).unwrap();
let indexed_pos = schema.set_indexed(&name).unwrap().1;
let index = DocIndex {
attribute: indexed_pos.0,
..*index
};
final_indexes.push(index);
}
let word = word.to_lowercase().into_bytes(); let word = word.to_lowercase().into_bytes();
words_fst.insert(word.clone()); words_fst.insert(word.clone());
postings_lists postings_lists
.entry(word) .entry(word)
.or_insert_with(Vec::new) .or_insert_with(Vec::new)
.extend_from_slice(indexes); .extend_from_slice(&final_indexes);
for idx in indexes { for idx in final_indexes {
fields_counts.insert((idx.document_id, idx.attribute, idx.word_index), 1); fields_counts.insert((idx.document_id, idx.attribute, idx.word_index), 1);
} }
} }
index.main.put_schema(&mut writer, &schema).unwrap();
let words_fst = Set::from_iter(words_fst).unwrap(); let words_fst = Set::from_iter(words_fst).unwrap();
index.main.put_words_fst(&mut writer, &words_fst).unwrap(); index.main.put_words_fst(&mut writer, &words_fst).unwrap();

View File

@ -44,8 +44,6 @@ pub fn apply_settings_update(
} }
}; };
println!("settings: {:?}", settings);
match settings.ranking_rules { match settings.ranking_rules {
UpdateState::Update(v) => { UpdateState::Update(v) => {
index.main.put_ranking_rules(writer, v)?; index.main.put_ranking_rules(writer, v)?;
@ -126,8 +124,6 @@ pub fn apply_settings_update(
index.main.put_schema(writer, &schema)?; index.main.put_schema(writer, &schema)?;
println!("schema: {:?}", schema);
match settings.stop_words { match settings.stop_words {
UpdateState::Update(stop_words) => { UpdateState::Update(stop_words) => {
if apply_stop_words_update(writer, index, stop_words)? { if apply_stop_words_update(writer, index, stop_words)? {

View File

@ -109,6 +109,9 @@ impl Schema {
pub fn set_indexed<S: Into<String>>(&mut self, name: S) -> SResult<(FieldId, IndexedPos)> { pub fn set_indexed<S: Into<String>>(&mut self, name: S) -> SResult<(FieldId, IndexedPos)> {
let id = self.fields_map.insert(name.into())?; let id = self.fields_map.insert(name.into())?;
if let Some(indexed_pos) = self.indexed_map.get(&id) {
return Ok((id, *indexed_pos))
};
let pos = self.indexed.len() as u16; let pos = self.indexed.len() as u16;
self.indexed.push(id); self.indexed.push(id);
self.indexed_map.insert(id, pos.into()); self.indexed_map.insert(id, pos.into());