pub fn add_document(&mut self, add_operation: AddOperation, schema: &Schema) -> io::Result<()> {
        let doc_id = self.max_doc;
        let mut doc = add_operation.document;
        self.doc_opstamps.push(add_operation.opstamp);

        self.fast_field_writers.add_document(&doc);

        for (field, field_values) in doc.get_sorted_field_values() {
            let field_options = schema.get_field_entry(field);
            if !field_options.is_indexed() {
                continue;
            }
            match *field_options.field_type() {
                FieldType::HierarchicalFacet => {
                    let facets: Vec<&str> = field_values
                        .iter()
                        .flat_map(|field_value| match *field_value.value() {
                            Value::Facet(ref facet) => Some(facet.encoded_str()),
                            _ => {
                                panic!("Expected hierarchical facet");
                            }
                        })
                        .collect();
                    let mut term = Term::for_field(field); // we set the Term
                    for fake_str in facets {
                        let mut unordered_term_id_opt = None;
                        FacetTokenizer.token_stream(fake_str).process(&mut |token| {
                            term.set_text(&token.text);
                            let unordered_term_id =
                                self.multifield_postings.subscribe(doc_id, &term);
                            unordered_term_id_opt = Some(unordered_term_id);
                        });
                        if let Some(unordered_term_id) = unordered_term_id_opt {
                            self.fast_field_writers
                                .get_multivalue_writer(field)
                                .expect("multified writer for facet missing")
                                .add_val(unordered_term_id);
                        }
                    }
                }
                FieldType::Str(_) => {
                    let num_tokens = if let Some(ref mut tokenizer) =
                        self.tokenizers[field.field_id() as usize]
                    {
                        let texts: Vec<&str> = field_values
                            .iter()
                            .flat_map(|field_value| match *field_value.value() {
                                Value::Str(ref text) => Some(text.as_str()),
                                _ => None,
                            })
                            .collect();
                        if texts.is_empty() {
                            0
                        } else {
                            let mut token_stream = tokenizer.token_stream_texts(&texts[..]);
                            self.multifield_postings
                                .index_text(doc_id, field, &mut token_stream)
                        }
                    } else {
                        0
                    };
                    self.fieldnorms_writer.record(doc_id, field, num_tokens);
                }
                FieldType::U64(ref int_option) => {
                    if int_option.is_indexed() {
                        for field_value in field_values {
                            let term = Term::from_field_u64(
                                field_value.field(),
                                field_value.value().u64_value(),
                            );
                            self.multifield_postings.subscribe(doc_id, &term);
                        }
                    }
                }
                FieldType::Date(ref int_option) => {
                    if int_option.is_indexed() {
                        for field_value in field_values {
                            let term = Term::from_field_i64(
                                field_value.field(),
                                field_value.value().date_value().timestamp(),
                            );
                            self.multifield_postings.subscribe(doc_id, &term);
                        }
                    }
                }
                FieldType::I64(ref int_option) => {
                    if int_option.is_indexed() {
                        for field_value in field_values {
                            let term = Term::from_field_i64(
                                field_value.field(),
                                field_value.value().i64_value(),
                            );
                            self.multifield_postings.subscribe(doc_id, &term);
                        }
                    }
                }
                FieldType::F64(ref int_option) => {
                    if int_option.is_indexed() {
                        for field_value in field_values {
                            let term = Term::from_field_f64(
                                field_value.field(),
                                field_value.value().f64_value(),
                            );
                            self.multifield_postings.subscribe(doc_id, &term);
                        }
                    }
                }
                FieldType::Bytes => {
                    // Do nothing. Bytes only supports fast fields.
                }
            }
        }
        doc.filter_fields(|field| schema.get_field_entry(field).is_stored());
        let doc_writer = self.segment_serializer.get_store_writer();
        doc_writer.store(&doc)?;
        self.max_doc += 1;
        Ok(())
    }
/// Indexes a new document
///
/// As a user, you should rather use `IndexWriter`'s add_document.
Indexes a new document
As a user, you should rather use `IndexWriter`'s add_document.
Indexes a new document As a user you should rather use ` IndexWriter ` ' s add_document .
pub fn add_document(&mut self, add_operation: AddOperation, schema: &Schema) -> io::Result<()> {
        let doc_id = self.max_doc;
        let mut doc = add_operation.document;
        self.doc_opstamps.push(add_operation.opstamp);
        self.fast_field_writers.add_document(&doc);
        for (field, field_values) in doc.get_sorted_field_values() {
            let field_options = schema.get_field_entry(field);
            if !field_options.is_indexed() {
                continue;
            }
            match *field_options.field_type() {
                FieldType::HierarchicalFacet => {
                    let facets: Vec<&str> = field_values
                        .iter()
                        .flat_map(|field_value| match *field_value.value() {
                            Value::Facet(ref facet) => Some(facet.encoded_str()),
                            _ => {
                                panic!("Expected hierarchical facet");
                            }
                        })
                        .collect();
                    let mut term = Term::for_field(field); // we set the Term
                    for fake_str in facets {
                        let mut unordered_term_id_opt = None;
                        FacetTokenizer.token_stream(fake_str).process(&mut |token| {
                            term.set_text(&token.text);
                            let unordered_term_id =
                                self.multifield_postings.subscribe(doc_id, &term);
                            unordered_term_id_opt = Some(unordered_term_id);
                        });
                        if let Some(unordered_term_id) = unordered_term_id_opt {
                            self.fast_field_writers
                                .get_multivalue_writer(field)
                                .expect("multified writer for facet missing")
                                .add_val(unordered_term_id);
                        }
                    }
                }
                FieldType::Str(_) => {
                    let num_tokens = if let Some(ref mut tokenizer) =
                        self.tokenizers[field.field_id() as usize]
                    {
                        let texts: Vec<&str> = field_values
                            .iter()
                            .flat_map(|field_value| match *field_value.value() {
                                Value::Str(ref text) => Some(text.as_str()),
                                _ => None,
                            })
                            .collect();
                        if texts.is_empty() {
                            0
                        } else {
                            let mut token_stream = tokenizer.token_stream_texts(&texts[..]);
                            self.multifield_postings
                                .index_text(doc_id, field, &mut token_stream)
                        }
                    } else {
                        0
                    };
                    self.fieldnorms_writer.record(doc_id, field, num_tokens);
                }
                FieldType::U64(ref int_option) => {
                    if int_option.is_indexed() {
                        for field_value in field_values {
                            let term = Term::from_field_u64(
                                field_value.field(),
                                field_value.value().u64_value(),
                            );
                            self.multifield_postings.subscribe(doc_id, &term);
                        }
                    }
                }
                FieldType::Date(ref int_option) => {
                    if int_option.is_indexed() {
                        for field_value in field_values {
                            let term = Term::from_field_i64(
                                field_value.field(),
                                field_value.value().date_value().timestamp(),
                            );
                            self.multifield_postings.subscribe(doc_id, &term);
                        }
                    }
                }
                FieldType::I64(ref int_option) => {
                    if int_option.is_indexed() {
                        for field_value in field_values {
                            let term = Term::from_field_i64(
                                field_value.field(),
                                field_value.value().i64_value(),
                            );
                            self.multifield_postings.subscribe(doc_id, &term);
                        }
                    }
                }
                FieldType::F64(ref int_option) => {
                    if int_option.is_indexed() {
                        for field_value in field_values {
                            let term = Term::from_field_f64(
                                field_value.field(),
                                field_value.value().f64_value(),
                            );
                            self.multifield_postings.subscribe(doc_id, &term);
                        }
                    }
                }
                FieldType::Bytes => {
                    // Do nothing. Bytes only supports fast fields.
                }
            }
        }
        doc.filter_fields(|field| schema.get_field_entry(field).is_stored());
        let doc_writer = self.segment_serializer.get_store_writer();
        doc_writer.store(&doc)?;
        self.max_doc += 1;
        Ok(())
    }
pub fn add_document ( & mut self , add_operation : AddOperation , schema : & Schema ) -> io :: Result < ( ) > { let doc_id = self . max_doc ; let mut doc = add_operation . document ; self . doc_opstamps . push ( add_operation . opstamp ) ; self . fast_field_writers . add_document ( & doc ) ; for ( field , field_values ) in doc . get_sorted_field_values ( ) { let field_options = schema . get_field_entry ( field ) ; if ! field_options . is_indexed ( ) { continue ; } match * field_options . field_type ( ) { FieldType :: HierarchicalFacet => { let facets : Vec < & str > = field_values . iter ( ) . flat_map ( | field_value | match * field_value . value ( ) { Value :: Facet ( ref facet ) => Some ( facet . encoded_str ( ) ) , _ => { panic ! ( " " ) ; } } ) . collect ( ) ; let mut term = Term :: for_field ( field ) ; // we set the Term for fake_str in facets { let mut unordered_term_id_opt = None ; FacetTokenizer . token_stream ( fake_str ) . process ( & mut | token | { term . set_text ( & token . text ) ; let unordered_term_id = self . multifield_postings . subscribe ( doc_id , & term ) ; unordered_term_id_opt = Some ( unordered_term_id ) ; } ) ; if let Some ( unordered_term_id ) = unordered_term_id_opt { self . fast_field_writers . get_multivalue_writer ( field ) . expect ( " " ) . add_val ( unordered_term_id ) ; } } } FieldType :: Str ( _ ) => { let num_tokens = if let Some ( ref mut tokenizer ) = self . tokenizers [ field . field_id ( ) as usize ] { let texts : Vec < & str > = field_values . iter ( ) . flat_map ( | field_value | match * field_value . value ( ) { Value :: Str ( ref text ) => Some ( text . as_str ( ) ) , _ => None , } ) . collect ( ) ; if texts . is_empty ( ) { 0 } else { let mut token_stream = tokenizer . token_stream_texts ( & texts [ .. ] ) ; self . multifield_postings . index_text ( doc_id , field , & mut token_stream ) } } else { 0 } ; self . fieldnorms_writer . record ( doc_id , field , num_tokens ) ; } FieldType :: U64 ( ref int_option ) => { if int_option . is_indexed ( ) { for field_value in field_values { let term = Term :: from_field_u64 ( field_value . field ( ) , field_value . value ( ) . u64_value ( ) , ) ; self . multifield_postings . subscribe ( doc_id , & term ) ; } } } FieldType :: Date ( ref int_option ) => { if int_option . is_indexed ( ) { for field_value in field_values { let term = Term :: from_field_i64 ( field_value . field ( ) , field_value . value ( ) . date_value ( ) . timestamp ( ) , ) ; self . multifield_postings . subscribe ( doc_id , & term ) ; } } } FieldType :: I64 ( ref int_option ) => { if int_option . is_indexed ( ) { for field_value in field_values { let term = Term :: from_field_i64 ( field_value . field ( ) , field_value . value ( ) . i64_value ( ) , ) ; self . multifield_postings . subscribe ( doc_id , & term ) ; } } } FieldType :: F64 ( ref int_option ) => { if int_option . is_indexed ( ) { for field_value in field_values { let term = Term :: from_field_f64 ( field_value . field ( ) , field_value . value ( ) . f64_value ( ) , ) ; self . multifield_postings . subscribe ( doc_id , & term ) ; } } } FieldType :: Bytes => { // Do nothing. Bytes only supports fast fields. } } } doc . filter_fields ( | field | schema . get_field_entry ( field ) . is_stored ( ) ) ; let doc_writer = self . segment_serializer . get_store_writer ( ) ; doc_writer . store ( & doc ) ? ; self . max_doc += 1 ; Ok ( ( ) ) }
Indexes a new document
As a user, you should rather use `IndexWriter`'s add_document.
Indexes a new document As a user you should rather use ` IndexWriter ` ' s add_document .
&mut self
add_operation
AddOperation
schema
&Schema
&mut self
add_operation
AddOperation
schema
&Schema