/// Unique word has multi-word synonyms
Unique word has multi-word synonyms
Unique word has multi - word synonyms
fn unique_to_multiword_synonyms() {
        let mut store = TempDatabase::from_iter(vec![
            ("new", &[doc_char_index(0, 0, 0)][..]),
            ("york", &[doc_char_index(0, 1, 1)][..]),
            ("city", &[doc_char_index(0, 2, 2)][..]),
            ("subway", &[doc_char_index(0, 3, 3)][..]),
            ("NY", &[doc_char_index(1, 0, 0)][..]),
            ("subway", &[doc_char_index(1, 1, 1)][..]),
        ]);
        store.add_synonym(
            "NY",
            SetBuf::from_dirty(vec!["NYC", "new york", "new york city"]),
        );
        store.add_synonym(
            "NYC",
            SetBuf::from_dirty(vec!["NY", "new york", "new york city"]),
        );
        let db = &store.database;
        let reader = db.main_read_txn().unwrap();
        let builder = store.query_builder();
        let SortResult { documents, .. } = builder.query(&reader, "NY subway", 0..20).unwrap();
        let mut iter = documents.into_iter();
        assert_matches!(iter.next(), Some(Document { id: DocumentId(1), matches, .. }) => {
            let mut iter = matches.into_iter();
            assert_matches!(iter.next(), Some(SimpleMatch { query_index: 0, word_index: 0, is_exact: true, .. })); // new  = NY
            assert_matches!(iter.next(), Some(SimpleMatch { query_index: 1, word_index: 1, is_exact: true, .. })); // york = NY
            assert_matches!(iter.next(), Some(SimpleMatch { query_index: 2, word_index: 2, is_exact: true, .. })); // city = NY
            assert_matches!(iter.next(), Some(SimpleMatch { query_index: 3, word_index: 3, is_exact: true,  .. })); // subway
            assert_matches!(iter.next(), None);                // position rewritten ^
        });
        assert_matches!(iter.next(), Some(Document { id: DocumentId(0), matches, .. }) => {
            let mut iter = matches.into_iter();
            assert_matches!(iter.next(), Some(SimpleMatch { query_index: 0, word_index: 0, is_exact: false, .. })); // NY ± new
            assert_matches!(iter.next(), Some(SimpleMatch { query_index: 1, word_index: 1, is_exact: false, .. })); // NY ± york
            assert_matches!(iter.next(), Some(SimpleMatch { query_index: 2, word_index: 2, is_exact: false, .. })); // NY ± city
            assert_matches!(iter.next(), Some(SimpleMatch { query_index: 3, word_index: 3, is_exact: true, .. })); // subway
            assert_matches!(iter.next(), None);
        });
        assert_matches!(iter.next(), None);
        let builder = store.query_builder();
        let SortResult { documents, .. } = builder.query(&reader, "NYC subway", 0..20).unwrap();
        let mut iter = documents.into_iter();
        assert_matches!(iter.next(), Some(Document { id: DocumentId(1), matches, .. }) => {
            let mut iter = matches.into_iter();
            assert_matches!(iter.next(), Some(SimpleMatch { query_index: 0, word_index: 0, is_exact: true, .. })); // new  = NYC
            assert_matches!(iter.next(), Some(SimpleMatch { query_index: 1, word_index: 1, is_exact: true, .. })); // york = NYC
            assert_matches!(iter.next(), Some(SimpleMatch { query_index: 2, word_index: 2, is_exact: true, .. })); // city = NYC
            assert_matches!(iter.next(), Some(SimpleMatch { query_index: 3, word_index: 3, is_exact: true,  .. })); // subway
            assert_matches!(iter.next(), None);                // position rewritten ^
        });
        assert_matches!(iter.next(), Some(Document { id: DocumentId(0), matches, .. }) => {
            let mut iter = matches.into_iter();
            assert_matches!(iter.next(), Some(SimpleMatch { query_index: 0, word_index: 0, is_exact: false, .. })); // NYC ± new
            assert_matches!(iter.next(), Some(SimpleMatch { query_index: 1, word_index: 1, is_exact: false, .. })); // NYC ± york
            assert_matches!(iter.next(), Some(SimpleMatch { query_index: 2, word_index: 2, is_exact: false, .. })); // NYC ± city
            assert_matches!(iter.next(), Some(SimpleMatch { query_index: 3, word_index: 3, is_exact: true, .. })); // subway
            assert_matches!(iter.next(), None);
        });
        assert_matches!(iter.next(), None);
    }
fn unique_to_multiword_synonyms ( ) { let mut store = TempDatabase :: from_iter ( vec ! [ ( " " [ doc_char_index ( 0 0 0 ) ] [ ] ) ( " " [ doc_char_index ( 0 1 1 ) ] [ ] ) ( " " [ doc_char_index ( 0 2 2 ) ] [ ] ) ( " " [ doc_char_index ( 0 3 3 ) ] [ ] ) ( " " [ doc_char_index ( 1 0 0 ) ] [ ] ) ( " " [ doc_char_index ( 1 1 1 ) ] [ ] ) ] ) ; store . add_synonym ( " " , SetBuf :: from_dirty ( vec ! [ " " " " " " ] ) , ) ; store . add_synonym ( " " , SetBuf :: from_dirty ( vec ! [ " " " " " " ] ) , ) ; let db = & store . database ; let reader = db . main_read_txn ( ) . unwrap ( ) ; let builder = store . query_builder ( ) ; let SortResult { documents , .. } = builder . query ( & reader , " " , 0 .. 20 ) . unwrap ( ) ; let mut iter = documents . into_iter ( ) ; assert_matches ! ( iter next ( ) Some ( Document { id DocumentId ( 1 ) matches } ) { let mut iter matches into_iter ( ) assert_matches ( iter next ( ) Some ( SimpleMatch { query_index 0 word_index 0 is_exact true } ) ) // new  = NY assert_matches ( iter next ( ) Some ( SimpleMatch { query_index 1 word_index 1 is_exact true } ) ) // york = NY assert_matches ( iter next ( ) Some ( SimpleMatch { query_index 2 word_index 2 is_exact true } ) ) // city = NY assert_matches ( iter next ( ) Some ( SimpleMatch { query_index 3 word_index 3 is_exact true } ) ) // subway assert_matches ( iter next ( ) None ) // position rewritten ^ } ) ; assert_matches ! ( iter next ( ) Some ( Document { id DocumentId ( 0 ) matches } ) { let mut iter matches into_iter ( ) assert_matches ( iter next ( ) Some ( SimpleMatch { query_index 0 word_index 0 is_exact false } ) ) // NY ± new assert_matches ( iter next ( ) Some ( SimpleMatch { query_index 1 word_index 1 is_exact false } ) ) // NY ± york assert_matches ( iter next ( ) Some ( SimpleMatch { query_index 2 word_index 2 is_exact false } ) ) // NY ± city assert_matches ( iter next ( ) Some ( SimpleMatch { query_index 3 word_index 3 is_exact true } ) ) // subway assert_matches ( iter next ( ) None ) } ) ; assert_matches ! ( iter next ( ) None ) ; let builder = store . query_builder ( ) ; let SortResult { documents , .. } = builder . query ( & reader , " " , 0 .. 20 ) . unwrap ( ) ; let mut iter = documents . into_iter ( ) ; assert_matches ! ( iter next ( ) Some ( Document { id DocumentId ( 1 ) matches } ) { let mut iter matches into_iter ( ) assert_matches ( iter next ( ) Some ( SimpleMatch { query_index 0 word_index 0 is_exact true } ) ) // new  = NYC assert_matches ( iter next ( ) Some ( SimpleMatch { query_index 1 word_index 1 is_exact true } ) ) // york = NYC assert_matches ( iter next ( ) Some ( SimpleMatch { query_index 2 word_index 2 is_exact true } ) ) // city = NYC assert_matches ( iter next ( ) Some ( SimpleMatch { query_index 3 word_index 3 is_exact true } ) ) // subway assert_matches ( iter next ( ) None ) // position rewritten ^ } ) ; assert_matches ! ( iter next ( ) Some ( Document { id DocumentId ( 0 ) matches } ) { let mut iter matches into_iter ( ) assert_matches ( iter next ( ) Some ( SimpleMatch { query_index 0 word_index 0 is_exact false } ) ) // NYC ± new assert_matches ( iter next ( ) Some ( SimpleMatch { query_index 1 word_index 1 is_exact false } ) ) // NYC ± york assert_matches ( iter next ( ) Some ( SimpleMatch { query_index 2 word_index 2 is_exact false } ) ) // NYC ± city assert_matches ( iter next ( ) Some ( SimpleMatch { query_index 3 word_index 3 is_exact true } ) ) // subway assert_matches ( iter next ( ) None ) } ) ; assert_matches ! ( iter next ( ) None ) ; }
Unique word has multi-word synonyms
Unique word has multi - word synonyms