mirror of
https://github.com/meilisearch/MeiliSearch
synced 2024-11-22 12:54:26 +01:00
fix schema & fix tests
This commit is contained in:
parent
116a637cfd
commit
ae0a11e422
@ -145,6 +145,7 @@ mod tests {
|
||||
use crate::bucket_sort::SimpleMatch;
|
||||
use crate::database::Database;
|
||||
use crate::store::Index;
|
||||
use meilisearch_schema::Schema;
|
||||
|
||||
fn set_from_stream<'f, I, S>(stream: I) -> Set
|
||||
where
|
||||
@ -268,18 +269,34 @@ mod tests {
|
||||
let mut postings_lists = HashMap::new();
|
||||
let mut fields_counts = HashMap::<_, u16>::new();
|
||||
|
||||
let mut schema = Schema::default();
|
||||
|
||||
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();
|
||||
words_fst.insert(word.clone());
|
||||
postings_lists
|
||||
.entry(word)
|
||||
.or_insert_with(Vec::new)
|
||||
.extend_from_slice(indexes);
|
||||
for idx in indexes {
|
||||
.extend_from_slice(&final_indexes);
|
||||
for idx in final_indexes {
|
||||
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();
|
||||
|
||||
index.main.put_words_fst(&mut writer, &words_fst).unwrap();
|
||||
|
@ -44,8 +44,6 @@ pub fn apply_settings_update(
|
||||
}
|
||||
};
|
||||
|
||||
println!("settings: {:?}", settings);
|
||||
|
||||
match settings.ranking_rules {
|
||||
UpdateState::Update(v) => {
|
||||
index.main.put_ranking_rules(writer, v)?;
|
||||
@ -126,8 +124,6 @@ pub fn apply_settings_update(
|
||||
|
||||
index.main.put_schema(writer, &schema)?;
|
||||
|
||||
println!("schema: {:?}", schema);
|
||||
|
||||
match settings.stop_words {
|
||||
UpdateState::Update(stop_words) => {
|
||||
if apply_stop_words_update(writer, index, stop_words)? {
|
||||
|
@ -109,6 +109,9 @@ impl Schema {
|
||||
|
||||
pub fn set_indexed<S: Into<String>>(&mut self, name: S) -> SResult<(FieldId, IndexedPos)> {
|
||||
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;
|
||||
self.indexed.push(id);
|
||||
self.indexed_map.insert(id, pos.into());
|
||||
|
Loading…
Reference in New Issue
Block a user