Repository: meilisearch/meilisearch
File: meilisearch-lib/src/index/search.rs (Rust)

Code before:
        obkv.insert(
            author,
            Value::String("J. K. Rowling".into()).to_string().as_bytes(),
        )
        .unwrap();
        obkv.finish().unwrap();

        let obkv = obkv::KvReader::new(&buf);

        let mut formatted_options = BTreeMap::new();
        formatted_options.insert(
            title,
            FormatOptions {
                highlight: false,
                crop: Some(0),
            },
        );
        formatted_options.insert(
            author,
            FormatOptions {
                highlight: false,
                crop: None,
            },
        );

        let mut matching_words = BTreeMap::new();
        matching_words.insert("potter", Some(6));

        let value = format_fields(
            &fields,
            obkv,
            &formatter,
            &matching_words,
            &formatted_options,
        )
        .unwrap();

        assert_eq!(value["title"], "Harry Potter and the Half-Blood Prince");
        assert_eq!(value["author"], "J. K. Rowling");
    }

    #[test]
    fn formatted_with_crop_and_no_match() {
        let stop_words = fst::Set::default();
        let mut config = AnalyzerConfig::default();
        config.stop_words(&stop_words);
        let analyzer = Analyzer::new(config);
        let formatter = Formatter::new(
            &analyzer,
            (String::from("<em>"), String::from("</em>")),
            String::from("…"),

Review comment (suggestion):
crop 0 behavior changes, we are now considering that crop 0 is equivalent to no crop.

https://github.com/meilisearch/specifications/blob/26937397f3d943717da72a67443080d185f78b49/text/0118-search-api.md?plain=1#L265

Code after:
            FormatOptions {
                highlight: false,
                crop: Some(0),
            },
        );
        formatted_options.insert(
            author,
            FormatOptions {
                highlight: false,
                crop: None,
            },
        );

        let mut matching_words = BTreeMap::new();
        matching_words.insert("potter", Some(6));

        let value = format_fields(
            &fields,
            obkv,
            &formatter,
            &matching_words,
            &formatted_options,
        )
        .unwrap();

        assert_eq!(value["title"], "Harry Potter and the Half-Blood Prince");
        assert_eq!(value["author"], "J. K. Rowling");
    }

    #[test]
    fn formatted_with_crop_and_no_match() {
        let stop_words = fst::Set::default();
        let mut config = AnalyzerConfig::default();
        config.stop_words(&stop_words);
        let analyzer = Analyzer::new(config);
        let formatter = Formatter::new(
            &analyzer,
            (String::from("<em>"), String::from("</em>")),
            String::from("…"),
        );

        let mut fields = FieldsIdsMap::new();
        let title = fields.insert("title").unwrap();
        let author = fields.insert("author").unwrap();

        let mut buf = Vec::new();
        let mut obkv = obkv::KvWriter::new(&mut buf);
        obkv.insert(
            title,
            Value::String("Harry Potter and the Half-Blood Prince".into())
                .to_string()