Skip to content

Commit

Permalink
Pass document by reference.
Browse files Browse the repository at this point in the history
  • Loading branch information
tmpfs committed Aug 11, 2022
1 parent a41b743 commit f2a54c3
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 26 deletions.
22 changes: 11 additions & 11 deletions src/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,15 +290,15 @@ pub fn add_document_to_index<T: Eq + Hash + Copy, D>(
tokenizer: Tokenizer,
filter: Filter,
key: T,
doc: D,
doc: &D,
) {
let docs = &mut index.docs;
let fields = &mut index.fields;
let mut field_length = vec![0; fields.len()];
let mut term_counts: HashMap<String, Vec<usize>> = HashMap::new();
let mut all_terms: Vec<String> = Vec::new();
for i in 0..fields.len() {
if let Some(field_value) = field_accessors[i](&doc) {
if let Some(field_value) = field_accessors[i](doc) {
let fields_len = fields.len();
let mut field_details = fields.get_mut(i).unwrap();

Expand Down Expand Up @@ -593,7 +593,7 @@ mod tests {
text: "a b c".to_string(),
};

add_document_to_index(&mut index, &field_accessors, tokenizer, filter, doc.id, doc);
add_document_to_index(&mut index, &field_accessors, tokenizer, filter, doc.id, &doc);

assert_eq!(index.docs.len(), 1);
let (_, added_doc) = index.docs.iter().next().unwrap();
Expand Down Expand Up @@ -655,7 +655,7 @@ mod tests {
tokenizer,
filter,
doc_1.id,
doc_1.clone(),
&doc_1,
);

add_document_to_index(
Expand All @@ -664,7 +664,7 @@ mod tests {
tokenizer,
filter,
doc_2.id,
doc_2.clone(),
&doc_2,
);

assert_eq!(index.docs.len(), 2);
Expand Down Expand Up @@ -725,7 +725,7 @@ mod tests {
tokenizer,
filter,
doc_1.id,
doc_1,
&doc_1,
);
}
}
Expand All @@ -751,7 +751,7 @@ mod tests {
tokenizer,
filter,
doc.id,
doc,
&doc,
)
}

Expand Down Expand Up @@ -871,14 +871,14 @@ mod tests {
text: "abe".to_string(),
};

add_document_to_index(&mut index, &field_accessors, tokenizer, filter, doc.id, doc);
add_document_to_index(&mut index, &field_accessors, tokenizer, filter, doc.id, &doc);
add_document_to_index(
&mut index,
&field_accessors,
tokenizer,
filter,
doc_2.id,
doc_2,
&doc_2,
);
assert_eq!(count_nodes(&index), 5); //
}
Expand All @@ -899,14 +899,14 @@ mod tests {
text: "ab ef".to_string(),
};

add_document_to_index(&mut index, &field_accessors, tokenizer, filter, doc.id, doc);
add_document_to_index(&mut index, &field_accessors, tokenizer, filter, doc.id, &doc);
add_document_to_index(
&mut index,
&field_accessors,
tokenizer,
filter,
doc_2.id,
doc_2,
&doc_2,
);
assert_eq!(count_nodes(&index), 7); //
}
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ pub mod test_util {
id: i,
title: title.to_string(),
};
add_document_to_index(&mut index, &[title_extract], tokenizer, filter, doc.id, doc);
add_document_to_index(&mut index, &[title_extract], tokenizer, filter, doc.id, &doc);
}
index
}
Expand Down
14 changes: 7 additions & 7 deletions src/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ mod tests {
tokenizer,
filter,
doc.id,
doc,
&doc,
);
}
let result = query(
Expand Down Expand Up @@ -301,7 +301,7 @@ mod tests {
tokenizer,
filter,
doc.id,
doc,
&doc,
);
}

Expand Down Expand Up @@ -357,7 +357,7 @@ mod tests {
tokenizer,
filter,
doc.id,
doc,
&doc,
);
}

Expand Down Expand Up @@ -401,7 +401,7 @@ mod tests {
tokenizer,
filter,
doc.id,
doc,
&doc,
);
}

Expand Down Expand Up @@ -446,7 +446,7 @@ mod tests {
tokenizer,
filter,
doc.id,
doc,
&doc,
);
}

Expand Down Expand Up @@ -505,7 +505,7 @@ mod tests {
tokenizer,
filter,
doc.id,
doc,
&doc,
);
}
let exp = expand_term(&index, &"a".to_string(), &index.arena_index);
Expand Down Expand Up @@ -535,7 +535,7 @@ mod tests {
tokenizer,
filter,
doc.id,
doc,
&doc,
);
}
let exp = expand_term(&index, &"x".to_string(), &index.arena_index);
Expand Down
4 changes: 2 additions & 2 deletions src/query/score/default/zero_to_one.rs
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ mod tests {
tokenizer,
filter,
doc.id,
doc,
&doc,
);
}

Expand Down Expand Up @@ -391,7 +391,7 @@ mod tests {
tokenizer,
filter,
doc.id,
doc,
&doc,
);
}

Expand Down
10 changes: 5 additions & 5 deletions tests/integrations_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ pub fn test_add_query_delete_bm25() {
tokenizer,
filter,
doc_1.id,
doc_1.clone(),
&doc_1,
);

add_document_to_index(
Expand All @@ -66,7 +66,7 @@ pub fn test_add_query_delete_bm25() {
tokenizer,
filter,
doc_2.id,
doc_2,
&doc_2,
);

// Search, expected 2 results
Expand Down Expand Up @@ -144,7 +144,7 @@ pub fn test_add_query_delete_zero_to_one() {
tokenizer,
filter,
doc_1.id,
doc_1.clone(),
&doc_1,
);

add_document_to_index(
Expand All @@ -153,7 +153,7 @@ pub fn test_add_query_delete_zero_to_one() {
tokenizer,
filter,
doc_2.id,
doc_2,
&doc_2,
);

// Search, expected 2 results
Expand Down Expand Up @@ -215,6 +215,6 @@ pub fn it_is_thread_safe() {
tokenizer,
filter,
doc_1.id,
doc_1.clone(),
&doc_1,
);
}

0 comments on commit f2a54c3

Please sign in to comment.