/// <summary>
        /// *****************************************************
        /// * SAMPLE USAGE                                      *
        /// *****************************************************
        /// </summary>
        void HowToUse(string searchString)
        {
            Query query = new QueryParser(Lucene.Net.Util.Version.LUCENE_29, "text", new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_29)).Parse(searchString);

            SimpleFacetedSearch sfs = new SimpleFacetedSearch(_Reader, new string[] { "source", "category" });

            SimpleFacetedSearch.Hits hits = sfs.Search(query, 10);

            long totalHits = hits.TotalHitCount;

            foreach (SimpleFacetedSearch.HitsPerFacet hpg in hits.HitsPerFacet)
            {
                long hitCountPerGroup = hpg.HitCount;
                SimpleFacetedSearch.FacetName facetName = hpg.Name;
                for (int i = 0; i < facetName.Length; i++)
                {
                    string part = facetName[i];
                }
                foreach (Document doc in hpg.Documents)
                {
                    string text = doc.GetField("text").StringValue;
                    System.Diagnostics.Debug.WriteLine(">>" + facetName + ": " + text);
                }
            }
        }
        public void Test5()
        {
            Query query = new MatchAllDocsQuery();

            SimpleFacetedSearch sfs = new SimpleFacetedSearch(_Reader, "category");

            SimpleFacetedSearch.Hits hits = sfs.Search(query);

            Assert.AreEqual(7, hits.TotalHitCount);
        }
        public void Test6()
        {
            Query query = new MatchAllDocsQuery();

            SimpleFacetedSearch sfs = new SimpleFacetedSearch(_Reader, "nosuchfield");

            SimpleFacetedSearch.Hits hits = sfs.Search(query);

            Assert.AreEqual(0, hits.TotalHitCount);
            Assert.AreEqual(0, hits.HitsPerFacet.Length);
        }
        public void Test3()
        {
            Query query = new QueryParser(Lucene.Net.Util.Version.LUCENE_29, "text", new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_29)).Parse("block*");

            SimpleFacetedSearch sfs = new SimpleFacetedSearch(_Reader, new string[] { "lang", "source", "category" });

            SimpleFacetedSearch.Hits hits = sfs.Search(query);

            Assert.AreEqual(6, hits.HitsPerFacet.Length);
            int nohit = 0;

            foreach (SimpleFacetedSearch.HitsPerFacet hpg in hits.HitsPerFacet)
            {
                //Test for [System.Collections.Generic.KeyNotFoundException : The given key was not present in the dictionary.]
                var x = hits[hpg.Name];
                var y = hits[hpg.Name.ToString()];

                if (hpg.Name[0] == "us" && hpg.Name[1] == "CCN" && hpg.Name[2] == "politics")
                {
                    Assert.AreEqual(1, hpg.HitCount);
                }
                else
                if (hpg.Name[0] == "en" && hpg.Name[1] == "BCC" && hpg.Name[2] == "tech")
                {
                    Assert.AreEqual(1, hpg.HitCount);
                }
                else
                if (hpg.Name[0] == "us" && hpg.Name[1] == "CCN" && hpg.Name[2] == "sport")
                {
                    Assert.AreEqual(1, hpg.HitCount);
                }
                else
                if (hpg.Name[0] == "en" && hpg.Name[1] == "CCN" && hpg.Name[2] == "tech")
                {
                    Assert.AreEqual(1, hpg.HitCount);
                }
                else
                {
                    nohit++;
                    Assert.AreEqual(0, hpg.HitCount);
                }
            }
            Assert.AreEqual(2, nohit);
            Assert.AreEqual(4, hits.TotalHitCount);

            foreach (SimpleFacetedSearch.HitsPerFacet hpg in hits.HitsPerFacet)
            {
                foreach (Document doc in hpg.Documents)
                {
                    string text = doc.GetField("text").StringValue;
                    Assert.IsTrue(text.Contains("block"));
                }
            }
        }
        public void Test4()
        {
            Query query = new QueryParser(Lucene.Net.Util.Version.LUCENE_29, "text", new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_29)).Parse("xxxxxxxxxxxxx");

            SimpleFacetedSearch sfs = new SimpleFacetedSearch(_Reader, "category");

            SimpleFacetedSearch.Hits hits = sfs.Search(query);

            Assert.AreEqual(4, hits.HitsPerFacet.Length);
            Assert.AreEqual(0, hits.HitsPerFacet[0].HitCount);
            Assert.AreEqual(0, hits.HitsPerFacet[1].HitCount);
            Assert.AreEqual(0, hits.HitsPerFacet[2].HitCount);
        }
        public void Test7()
        {
            Query query = new QueryParser(Lucene.Net.Util.Version.LUCENE_29, "text", new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_29)).Parse("a");

            SimpleFacetedSearch sfs = new SimpleFacetedSearch(_Reader, "category");

            SimpleFacetedSearch.Hits hits = sfs.Search(query);

            Assert.AreEqual(0, hits.TotalHitCount, "Unexpected TotalHitCount");
            foreach (var x in hits.HitsPerFacet.Where(h => h.HitCount > 0))
            {
                Assert.Fail("There must be no hit");
            }
        }
        public void Test2()
        {
            Query query = new QueryParser(Lucene.Net.Util.Version.LUCENE_29, "text", new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_29)).Parse("block*");

            SimpleFacetedSearch sfs = new SimpleFacetedSearch(_Reader, "category");

            SimpleFacetedSearch.Hits hits = sfs.Search(query);

            Assert.AreEqual(4, hits.HitsPerFacet.Length);

            foreach (SimpleFacetedSearch.HitsPerFacet hpg in hits.HitsPerFacet)
            {
                if (hpg.Name[0] == "politics")
                {
                    Assert.AreEqual(1, hpg.HitCount);
                }
                else
                if (hpg.Name[0] == "tech")
                {
                    Assert.AreEqual(2, hpg.HitCount);
                }
                else
                if (hpg.Name[0] == "sport")
                {
                    Assert.AreEqual(1, hpg.HitCount);
                }
                else
                {
                    Assert.AreEqual(0, hpg.HitCount);
                }
            }

            Assert.AreEqual(4, hits.TotalHitCount);

            foreach (SimpleFacetedSearch.HitsPerFacet hpg in hits.HitsPerFacet)
            {
                foreach (Document doc in hpg.Documents)
                {
                    string text = doc.GetField("text").StringValue;
                    Assert.IsTrue(text.Contains("block"));
                }
            }
        }
        void MultiThreadedAccessThread(object o)
        {
            SimpleFacetedSearch sfs = (SimpleFacetedSearch)o;

            Query query = new QueryParser(Lucene.Net.Util.Version.LUCENE_29, "text", new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_29)).Parse("block*");

            for (int i = 0; i < 2000; i++)
            {
                SimpleFacetedSearch.Hits hits = sfs.Search(query);

                if (6 != hits.HitsPerFacet.Length)
                {
                    _errorCount++;
                }

                foreach (SimpleFacetedSearch.HitsPerFacet hpg in hits.HitsPerFacet)
                {
                    if (hpg.Name[0] == "us" && hpg.Name[1] == "CCN" && hpg.Name[2] == "politics")
                    {
                        if (1 != hpg.HitCount)
                        {
                            _errorCount++;
                        }
                    }
                    else
                    if (hpg.Name[0] == "en" && hpg.Name[1] == "BCC" && hpg.Name[2] == "tech")
                    {
                        if (1 != hpg.HitCount)
                        {
                            _errorCount++;
                        }
                    }
                    else
                    if (hpg.Name[0] == "us" && hpg.Name[1] == "CCN" && hpg.Name[2] == "sport")
                    {
                        if (1 != hpg.HitCount)
                        {
                            _errorCount++;
                        }
                    }
                    else
                    if (hpg.Name[0] == "en" && hpg.Name[1] == "CCN" && hpg.Name[2] == "tech")
                    {
                        if (1 != hpg.HitCount)
                        {
                            _errorCount++;
                        }
                    }
                    else
                    {
                        if (0 != hpg.HitCount)
                        {
                            _errorCount++;
                        }
                    }

                    if (4 != hits.TotalHitCount)
                    {
                        _errorCount++;
                    }
                }
            }
        }