public void TestClosestEditDistanceMatchComesFirst()
        {
            FuzzyLikeThisQuery flt = new FuzzyLikeThisQuery(10, analyzer);

            flt.AddTerms("smith", "name", 0.3f, 1);
            Query          q          = flt.Rewrite(searcher.IndexReader);
            HashSet <Term> queryTerms = new HashSet <Term>();

            q.ExtractTerms(queryTerms);
            assertTrue("Should have variant smythe", queryTerms.contains(new Term("name", "smythe")));
            assertTrue("Should have variant smith", queryTerms.contains(new Term("name", "smith")));
            assertTrue("Should have variant smyth", queryTerms.contains(new Term("name", "smyth")));
            TopDocs topDocs = searcher.Search(flt, 1);

            ScoreDoc[] sd = topDocs.ScoreDocs;
            assertTrue("score docs must match 1 doc", (sd != null) && (sd.Length > 0));
            Document doc = searcher.Doc(sd[0].Doc);

            assertEquals("Should match most similar not most rare variant", "2", doc.Get("id"));
        }
        public void TestNonExistingField()
        {
            FuzzyLikeThisQuery flt = new FuzzyLikeThisQuery(10, analyzer);

            flt.AddTerms("jonathin smoth", "name", 0.3f, 1);
            flt.AddTerms("jonathin smoth", "this field does not exist", 0.3f, 1);
            // don't fail here just because the field doesn't exits
            Query          q          = flt.Rewrite(searcher.IndexReader);
            HashSet <Term> queryTerms = new HashSet <Term>();

            q.ExtractTerms(queryTerms);
            assertTrue("Should have variant jonathan", queryTerms.contains(new Term("name", "jonathan")));
            assertTrue("Should have variant smith", queryTerms.contains(new Term("name", "smith")));
            TopDocs topDocs = searcher.Search(flt, 1);

            ScoreDoc[] sd = topDocs.ScoreDocs;
            assertTrue("score docs must match 1 doc", (sd != null) && (sd.Length > 0));
            Document doc = searcher.Doc(sd[0].Doc);

            assertEquals("Should match most similar when using 2 words", "2", doc.Get("id"));
        }