NOBUG add_document does not return result

This commit is contained in:
Paul Masurel
2017-02-27 09:36:41 +09:00
parent 7a07144c68
commit 15b60d72cc
10 changed files with 70 additions and 69 deletions

View File

@@ -95,7 +95,7 @@ fn run_example(index_path: &Path) -> tantivy::Result<()> {
old_man_doc.add_text(body, "He was an old man who fished alone in a skiff in the Gulf Stream and he had gone eighty-four days now without taking a fish.");
// ... and add it to the `IndexWriter`.
try!(index_writer.add_document(old_man_doc));
index_writer.add_document(old_man_doc);
// ### Create a document directly from json.
//
@@ -107,7 +107,7 @@ fn run_example(index_path: &Path) -> tantivy::Result<()> {
"body": "few miles south of Soledad, the Salinas River drops in close to the hillside bank and runs deep and green. The water is warm too, for it has slipped twinkling over the yellow sands in the sunlight before reaching the narrow pool. On one side of the river the golden foothill slopes curve up to the strong and rocky Gabilan Mountains, but on the valley side the water is lined with trees—willows fresh and green with every spring, carrying in their lower leaf junctures the debris of the winters flooding; and sycamores with mottled, white,recumbent limbs and branches that arch over the pool"
}"#));
try!(index_writer.add_document(mice_and_men_doc));
index_writer.add_document(mice_and_men_doc);
// Multi-valued field are allowed, they are
// expressed in JSON by an array.
@@ -116,7 +116,7 @@ fn run_example(index_path: &Path) -> tantivy::Result<()> {
"title": ["Frankenstein", "The Modern Promotheus"],
"body": "You will rejoice to hear that no disaster has accompanied the commencement of an enterprise which you have regarded with such evil forebodings. I arrived here yesterday, and my first task is to assure my dear sister of my welfare and increasing confidence in the success of my undertaking."
}"#));
try!(index_writer.add_document(frankenstein_doc));
index_writer.add_document(frankenstein_doc);
// This is an example, so we will only index 3 documents
// here. You can check out tantivy's tutorial to index

View File

@@ -149,7 +149,7 @@ mod tests {
{
let mut doc = Document::default();
doc.add_text(text_field, "a b d f");
index_writer.add_document(doc).unwrap();
index_writer.add_document(doc);
}
index_writer.commit().unwrap();
}
@@ -157,7 +157,7 @@ mod tests {
{
let mut doc = Document::default();
doc.add_text(text_field, "a b c d f");
index_writer.add_document(doc).unwrap();
index_writer.add_document(doc);
}
index_writer.commit().unwrap();
}
@@ -165,7 +165,7 @@ mod tests {
{
let mut doc = Document::default();
doc.add_text(text_field, "e f");
index_writer.add_document(doc).unwrap();
index_writer.add_document(doc);
}
index_writer.commit().unwrap();
}

View File

@@ -1,5 +1,5 @@
use std::collections::HashSet;
use rand::{thread_rng, Rng};
use rand::thread_rng;
use schema::*;
use Index;
@@ -30,7 +30,7 @@ fn test_indexing() {
let mut committed_docs: HashSet<u32> = HashSet::new();
let mut uncommitted_docs: HashSet<u32> = HashSet::new();
for n in 0..200 {
for _ in 0..200 {
let random_val = universe.ind_sample(&mut rng);
if random_val == 0 {
index_writer.commit();

View File

@@ -24,7 +24,6 @@ use Result;
use schema::Document;
use schema::Schema;
use schema::Term;
use std::io;
use std::mem;
use std::mem::swap;
use std::thread;
@@ -196,6 +195,10 @@ pub fn advance_deletes(
last_opstamp_opt = Some(delete_op.opstamp);
}
// we only write the result different
// iff we ended ended up increasing the delete opstamp
//
// TODO just move the file if there was no new delete?
if let Some(last_opstamp) = last_opstamp_opt {
for doc in 0u32..segment_reader.max_doc() {
if segment_reader.is_deleted(doc) {
@@ -518,16 +521,14 @@ impl IndexWriter {
///
/// Currently it represents the number of documents that
/// have been added since the creation of the index.
// TODO remove return without Result<>
pub fn add_document(&mut self, document: Document) -> io::Result<u64> {
pub fn add_document(&mut self, document: Document) -> u64 {
let opstamp = self.stamp();
let add_operation = AddOperation {
opstamp: opstamp,
document: document,
};
self.document_sender.send(add_operation);
Ok(opstamp)
opstamp
}
}
@@ -595,7 +596,7 @@ mod tests {
{
let mut doc = Document::default();
doc.add_text(text_field, "a");
index_writer.add_document(doc).unwrap();
index_writer.add_document(doc);
}
assert_eq!(index_writer.rollback().unwrap(), 0u64);
assert_eq!(num_docs_containing("a"), 0);
@@ -603,12 +604,12 @@ mod tests {
{
let mut doc = Document::default();
doc.add_text(text_field, "b");
index_writer.add_document(doc).unwrap();
index_writer.add_document(doc);
}
{
let mut doc = Document::default();
doc.add_text(text_field, "c");
index_writer.add_document(doc).unwrap();
index_writer.add_document(doc);
}
assert_eq!(index_writer.commit().unwrap(), 2u64);
index.load_searchers().unwrap();
@@ -637,13 +638,13 @@ mod tests {
for _doc in 0..100 {
let mut doc = Document::default();
doc.add_text(text_field, "a");
index_writer.add_document(doc).unwrap();
index_writer.add_document(doc);
}
index_writer.commit().expect("commit failed");
for _doc in 0..100 {
let mut doc = Document::default();
doc.add_text(text_field, "a");
index_writer.add_document(doc).unwrap();
index_writer.add_document(doc);
}
// this should create 8 segments and trigger a merge.
index_writer.commit().expect("commit failed");

View File

@@ -325,19 +325,19 @@ mod tests {
let mut doc = Document::default();
doc.add_text(text_field, "af b");
doc.add_u32(score_field, 3);
index_writer.add_document(doc).unwrap();
index_writer.add_document(doc);
}
{
let mut doc = Document::default();
doc.add_text(text_field, "a b c");
doc.add_u32(score_field, 5);
index_writer.add_document(doc).unwrap();
index_writer.add_document(doc);
}
{
let mut doc = Document::default();
doc.add_text(text_field, "a b c d");
doc.add_u32(score_field, 7);
index_writer.add_document(doc).unwrap();
index_writer.add_document(doc);
}
index_writer.commit().expect("committed");
}
@@ -348,13 +348,13 @@ mod tests {
let mut doc = Document::default();
doc.add_text(text_field, "af b");
doc.add_u32(score_field, 11);
index_writer.add_document(doc).unwrap();
index_writer.add_document(doc);
}
{
let mut doc = Document::default();
doc.add_text(text_field, "a b c g");
doc.add_u32(score_field, 13);
index_writer.add_document(doc).unwrap();
index_writer.add_document(doc);
}
index_writer.commit().expect("Commit failed");
}
@@ -443,18 +443,18 @@ mod tests {
doc!(
text_field => "a b d",
score_field => 1
)).unwrap();
));
index_writer.add_document(
doc!(
text_field => "b c",
score_field => 2
)).unwrap();
));
index_writer.delete_term(Term::from_field_text(text_field, "c"));
index_writer.add_document(
doc!(
text_field => "c d",
score_field => 3
)).unwrap();
));
index_writer.commit().expect("committed");
index.load_searchers().unwrap();
let ref searcher = *index.searcher();
@@ -471,24 +471,24 @@ mod tests {
doc!(
text_field => "a d e",
score_field => 4_000
)).unwrap();
));
index_writer.add_document(
doc!(
text_field => "e f",
score_field => 5_000
)).unwrap();
));
index_writer.delete_term(Term::from_field_text(text_field, "a"));
index_writer.delete_term(Term::from_field_text(text_field, "f"));
index_writer.add_document(
doc!(
text_field => "f g",
score_field => 6_000
)).unwrap();
));
index_writer.add_document(
doc!(
text_field => "g h",
score_field => 7_000
)).unwrap();
));
index_writer.commit().expect("committed");
index.load_searchers().unwrap();
let searcher = index.searcher();

View File

@@ -206,15 +206,15 @@ mod tests {
let mut index_writer = index.writer_with_num_threads(1, 40_000_000).unwrap();
{
let doc = doc!(text_field=>"af b");
index_writer.add_document(doc).unwrap();
index_writer.add_document(doc);
}
{
let doc = doc!(text_field=>"a b c");
index_writer.add_document(doc).unwrap();
index_writer.add_document(doc);
}
{
let doc = doc!(text_field=>"a b c d");
index_writer.add_document(doc).unwrap();
index_writer.add_document(doc);
}
assert!(index_writer.commit().is_ok());
}
@@ -228,23 +228,23 @@ mod tests {
let index = Index::create_in_ram(schema_builder.build());
let mut index_writer = index.writer_with_num_threads(1, 40_000_000).unwrap();
{
index_writer.add_document(doc!(text_field=>"a b c")).unwrap();
index_writer.add_document(doc!(text_field=>"a b c"));
index_writer.commit().unwrap();
}
{
{
let doc = doc!(text_field=>"a");
index_writer.add_document(doc).unwrap();
index_writer.add_document(doc);
}
{
let doc = doc!(text_field=>"a a");
index_writer.add_document(doc).unwrap();
index_writer.add_document(doc);
}
index_writer.commit().unwrap();
}
{
let doc = doc!(text_field=>"c");
index_writer.add_document(doc).unwrap();
index_writer.add_document(doc);
index_writer.commit().unwrap();
}
{
@@ -271,15 +271,15 @@ mod tests {
let mut index_writer = index.writer_with_num_threads(1, 40_000_000).unwrap();
{
let doc = doc!(text_field=>"a b c");
index_writer.add_document(doc).unwrap();
index_writer.add_document(doc);
}
{
let doc = doc!();
index_writer.add_document(doc).unwrap();
index_writer.add_document(doc);
}
{
let doc = doc!(text_field=>"a b");
index_writer.add_document(doc).unwrap();
index_writer.add_document(doc);
}
index_writer.commit().unwrap();
}
@@ -306,19 +306,19 @@ mod tests {
let mut index_writer = index.writer_with_num_threads(1, 40_000_000).unwrap();
{ // 0
let doc = doc!(text_field=>"a b");
index_writer.add_document(doc).unwrap();
index_writer.add_document(doc);
}
{ // 1
let doc = doc!(text_field=>" a c");
index_writer.add_document(doc).unwrap();
index_writer.add_document(doc);
}
{ // 2
let doc = doc!(text_field=>" b c");
index_writer.add_document(doc).unwrap();
index_writer.add_document(doc);
}
{ // 3
let doc = doc!(text_field=>" b d");
index_writer.add_document(doc).unwrap();
index_writer.add_document(doc);
}
{
index_writer.delete_term(Term::from_field_text(text_field, "c"));
@@ -328,11 +328,11 @@ mod tests {
}
{ // 4
let doc = doc!(text_field=>" b c");
index_writer.add_document(doc).unwrap();
index_writer.add_document(doc);
}
{ // 5
let doc = doc!(text_field=>" a");
index_writer.add_document(doc).unwrap();
index_writer.add_document(doc);
}
index_writer.commit().unwrap();
}
@@ -361,7 +361,7 @@ mod tests {
let mut index_writer = index.writer_with_num_threads(1, 40_000_000).unwrap();
{ // 0
let doc = doc!(text_field=>"a b");
index_writer.add_document(doc).unwrap();
index_writer.add_document(doc);
}
{ // 1
index_writer.delete_term(Term::from_field_text(text_field, "c"));
@@ -393,7 +393,7 @@ mod tests {
let mut index_writer = index.writer_with_num_threads(1, 40_000_000).unwrap();
{
let doc = doc!(text_field=>"a b");
index_writer.add_document(doc).unwrap();
index_writer.add_document(doc);
}
{
index_writer.delete_term(Term::from_field_text(text_field, "c"));
@@ -497,7 +497,7 @@ mod tests {
let mut index_writer = index.writer_with_num_threads(1, 40_000_000).unwrap();
{
let doc = doc!(text_field=>"af af af bc bc");
index_writer.add_document(doc).unwrap();
index_writer.add_document(doc);
}
index_writer.commit().unwrap();
}
@@ -526,15 +526,15 @@ mod tests {
let mut index_writer = index.writer_with_num_threads(1, 40_000_000).unwrap();
{
let doc = doc!(text_field=>"af af af b");
index_writer.add_document(doc).unwrap();
index_writer.add_document(doc);
}
{
let doc = doc!(text_field=>"a b c");
index_writer.add_document(doc).unwrap();
index_writer.add_document(doc);
}
{
let doc = doc!(text_field=>"a b c d");
index_writer.add_document(doc).unwrap();
index_writer.add_document(doc);
}
index_writer.commit().unwrap();
}
@@ -593,15 +593,15 @@ mod tests {
let mut index_writer = index.writer_with_num_threads(1, 40_000_000).unwrap();
{
let doc = doc!(text_field=>"af b");
index_writer.add_document(doc).unwrap();
index_writer.add_document(doc);
}
{
let doc = doc!(text_field=>"a b c");
index_writer.add_document(doc).unwrap();
index_writer.add_document(doc);
}
{
let doc = doc!(text_field=>"a b c d");
index_writer.add_document(doc).unwrap();
index_writer.add_document(doc);
}
index_writer.commit().unwrap();
}

View File

@@ -175,12 +175,12 @@ mod tests {
{
let mut doc = Document::default();
doc.add_text(text_field, "g b b d c g c");
index_writer.add_document(doc).unwrap();
index_writer.add_document(doc);
}
{
let mut doc = Document::default();
doc.add_text(text_field, "g a b b a d c g c");
index_writer.add_document(doc).unwrap();
index_writer.add_document(doc);
}
assert!(index_writer.commit().is_ok());
}
@@ -257,7 +257,7 @@ mod tests {
count_b += 1;
doc.add_text(text_field, "b");
}
index_writer.add_document(doc).unwrap();
index_writer.add_document(doc);
}
assert!(index_writer.commit().is_ok());
}

View File

@@ -42,23 +42,23 @@ mod tests {
let mut index_writer = index.writer_with_num_threads(1, 40_000_000).unwrap();
{
let doc = doc!(text_field => "a b c");
index_writer.add_document(doc).unwrap();
index_writer.add_document(doc);
}
{
let doc = doc!(text_field => "a c");
index_writer.add_document(doc).unwrap();
index_writer.add_document(doc);
}
{
let doc = doc!(text_field => "b c");
index_writer.add_document(doc).unwrap();
index_writer.add_document(doc);
}
{
let doc = doc!(text_field => "a b c d");
index_writer.add_document(doc).unwrap();
index_writer.add_document(doc);
}
{
let doc = doc!(text_field => "d");
index_writer.add_document(doc).unwrap();
index_writer.add_document(doc);
}
assert!(index_writer.commit().is_ok());
}

View File

@@ -27,23 +27,23 @@ mod tests {
let mut index_writer = index.writer_with_num_threads(1, 40_000_000).unwrap();
{ // 0
let doc = doc!(text_field=>"b b b d c g c");
index_writer.add_document(doc).unwrap();
index_writer.add_document(doc);
}
{ // 1
let doc = doc!(text_field=>"a b b d c g c");
index_writer.add_document(doc).unwrap();
index_writer.add_document(doc);
}
{ // 2
let doc = doc!(text_field=>"a b a b c");
index_writer.add_document(doc).unwrap();
index_writer.add_document(doc);
}
{ // 3
let doc = doc!(text_field=>"c a b a d ga a");
index_writer.add_document(doc).unwrap();
index_writer.add_document(doc);
}
{ // 4
let doc = doc!(text_field=>"a b c");
index_writer.add_document(doc).unwrap();
index_writer.add_document(doc);
}
assert!(index_writer.commit().is_ok());
}

View File

@@ -36,7 +36,7 @@ mod tests {
let mut index_writer = index.writer_with_num_threads(1, 40_000_000).unwrap();
{
let doc = doc!(text_field => "a");
index_writer.add_document(doc).unwrap();
index_writer.add_document(doc);
}
assert!(index_writer.commit().is_ok());
}