Esempio n. 1
0
        public void SimpleTermFacet()
        {
            ISearchResponse <ElasticsearchProject> queryResults = this.SearchRaw <ElasticsearchProject>(
                @" { ""query"" : {
							""match_all"" : { }
					},
					""facets"" : {
					  ""followers.lastName"" : { ""terms"" : {""field"" : ""followers.lastName""} }
					}
				}"
                );

            var facet = queryResults.Facets["followers.lastName"];

            this.TestDefaultAssertions(queryResults);
            Assert.IsInstanceOf <TermFacet>(facet);
            var tf = (TermFacet)facet;

            Assert.AreEqual(0, tf.Missing);
            Assert.Greater(tf.Other, 0);
            Assert.Greater(tf.Total, 0);
            Assert.Greater(tf.Items.Count(), 0);

            foreach (TermItem term in tf.Items)
            {
                Assert.Greater(term.Count, 0);
                Assert.IsNotNullOrEmpty(term.Term);
            }

            tf = queryResults.Facet <TermFacet>(p => p.Followers.Select(f => f.LastName));
            Assert.AreEqual(0, tf.Missing);
            Assert.Greater(tf.Other, 0);
            Assert.Greater(tf.Total, 0);
            Assert.Greater(tf.Items.Count(), 0);

            var items = queryResults.FacetItems <TermItem>(p => p.Followers.Select(f => f.LastName));

            foreach (var i in items)
            {
                Assert.Greater(i.Count, 0);
                Assert.IsNotNullOrEmpty(i.Term);
            }
        }