update codebase with shcema refactor

This commit is contained in:
mpostma 2020-12-15 12:04:51 +01:00
parent 54686b0505
commit 2904ca7f57
9 changed files with 27 additions and 28 deletions

View file

@ -350,7 +350,7 @@ impl Database {
index.main.put_name(&mut writer, name)?;
index.main.put_created_at(&mut writer)?;
index.main.put_updated_at(&mut writer)?;
index.main.put_schema(&mut writer, &Schema::new())?;
index.main.put_schema(&mut writer, &Schema::default())?;
let env_clone = self.env.clone();
let update_env_clone = self.update_env.clone();

View file

@ -245,8 +245,8 @@ mod test {
#[test]
fn test_facet_key() {
let mut schema = Schema::new();
let id = schema.insert_and_index("hello").unwrap();
let mut schema = Schema::default();
let id = schema.insert_with_position("hello").unwrap().0;
let facet_list = [schema.id("hello").unwrap()];
assert_eq!(
FacetKey::from_str("hello:12", &schema, &facet_list).unwrap(),
@ -286,8 +286,8 @@ mod test {
#[test]
fn test_parse_facet_array() {
use either::Either::{Left, Right};
let mut schema = Schema::new();
let _id = schema.insert_and_index("hello").unwrap();
let mut schema = Schema::default();
let _id = schema.insert_with_position("hello").unwrap();
let facet_list = [schema.id("hello").unwrap()];
assert_eq!(
FacetFilter::from_str("[[\"hello:12\"]]", &schema, &facet_list).unwrap(),

View file

@ -415,8 +415,7 @@ mod tests {
let mut final_indexes = Vec::new();
for index in indexes {
let name = index.attribute.to_string();
schema.insert(&name).unwrap();
let indexed_pos = schema.set_indexed(&name).unwrap().1;
let indexed_pos = schema.insert_with_position(&name).unwrap().1;
let index = DocIndex {
attribute: indexed_pos.0,
..*index
@ -447,7 +446,7 @@ mod tests {
.postings_lists
.put_postings_list(&mut writer, &word, &postings_list)
.unwrap();
}
}
for ((docid, attr, _), count) in fields_counts {
let prev = index
@ -461,7 +460,7 @@ mod tests {
.documents_fields_counts
.put_document_field_count(&mut writer, docid, IndexedPos(attr), prev + count)
.unwrap();
}
}
writer.commit().unwrap();

View file

@ -13,7 +13,7 @@ static RANKING_RULE_REGEX: Lazy<regex::Regex> = Lazy::new(|| {
regex::Regex::new(r"(asc|desc)\(([a-zA-Z0-9-_]*)\)").unwrap()
});
#[derive(Default, Clone, Serialize, Deserialize)]
#[derive(Default, Clone, Serialize, Deserialize, Debug)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
pub struct Settings {
#[serde(default, deserialize_with = "deserialize_some")]

View file

@ -126,13 +126,13 @@ where A: AsRef<[u8]>,
let serialized = serde_json::to_vec(value)?;
documents_fields.put_document_field(writer, document_id, field_id, &serialized)?;
if let Some(indexed_pos) = schema.is_indexed(field_id) {
let number_of_words = index_value(indexer, document_id, *indexed_pos, value);
if let Some(indexed_pos) = schema.is_searchable(field_id) {
let number_of_words = index_value(indexer, document_id, indexed_pos, value);
if let Some(number_of_words) = number_of_words {
documents_fields_counts.put_document_field_count(
writer,
document_id,
*indexed_pos,
indexed_pos,
number_of_words as u16,
)?;
}
@ -228,7 +228,7 @@ pub fn apply_addition<'a, 'b, 'c>(
for (document_id, document) in &documents_additions {
// For each key-value pair in the document.
for (attribute, value) in document {
let field_id = schema.insert_and_index(&attribute)?;
let (field_id, _) = schema.insert_with_position(&attribute)?;
index_document(
writer,
index.documents_fields,

View file

@ -71,14 +71,14 @@ pub fn apply_settings_update(
match settings.searchable_attributes.clone() {
UpdateState::Update(v) => {
if v.iter().any(|e| e == "*") || v.is_empty() {
schema.set_all_fields_as_indexed();
schema.set_all_searchable();
} else {
schema.update_indexed(v)?;
schema.update_searchable(v)?;
}
must_reindex = true;
},
UpdateState::Clear => {
schema.set_all_fields_as_indexed();
schema.set_all_searchable();
must_reindex = true;
},
UpdateState::Nothing => (),
@ -86,13 +86,13 @@ pub fn apply_settings_update(
match settings.displayed_attributes.clone() {
UpdateState::Update(v) => {
if v.contains("*") || v.is_empty() {
schema.set_all_fields_as_displayed();
schema.set_all_displayed();
} else {
schema.update_displayed(v)?
}
},
UpdateState::Clear => {
schema.set_all_fields_as_displayed();
schema.set_all_displayed();
},
UpdateState::Nothing => (),
}