Maps specified dims to provided Facets impls; else, uses the default Facets impl.
Inheritance: Lucene.Net.Facet.Facets
Ejemplo n.º 1
0
        public virtual void TestSomeSameSomeDifferent()
        {
            Directory indexDir = NewDirectory();
            Directory taxoDir  = NewDirectory();

            // create and open an index writer
            RandomIndexWriter iw = new RandomIndexWriter(Random, indexDir, NewIndexWriterConfig(
                                                             TEST_VERSION_CURRENT, new MockAnalyzer(Random, MockTokenizer.WHITESPACE, false)));
            // create and open a taxonomy writer
            ITaxonomyWriter tw = new DirectoryTaxonomyWriter(taxoDir, OpenMode.CREATE);

            FacetsConfig config = GetConfig();

            config.SetIndexFieldName("Band", "$music");
            config.SetIndexFieldName("Composer", "$music");
            config.SetIndexFieldName("Author", "$literature");
            seedIndex(tw, iw, config);

            IndexReader ir = iw.GetReader();

            tw.Commit();

            // prepare index reader and taxonomy.
            var tr = new DirectoryTaxonomyReader(taxoDir);

            // prepare searcher to search against
            IndexSearcher searcher = NewSearcher(ir);

            FacetsCollector sfc = PerformSearch(tr, ir, searcher);

            IDictionary <string, Facets> facetsMap = new Dictionary <string, Facets>();
            Facets facets2 = GetTaxonomyFacetCounts(tr, config, sfc, "$music");

            facetsMap["Band"]     = facets2;
            facetsMap["Composer"] = facets2;
            facetsMap["Author"]   = GetTaxonomyFacetCounts(tr, config, sfc, "$literature");
            Facets facets = new MultiFacets(facetsMap, GetTaxonomyFacetCounts(tr, config, sfc));

            // Obtain facets results and hand-test them
            AssertCorrectResults(facets);
            assertOrdinalsExist("$music", ir);
            assertOrdinalsExist("$literature", ir);

            IOUtils.Dispose(tr, ir, iw, tw);
            IOUtils.Dispose(indexDir, taxoDir);
        }
        public virtual void TestCustom()
        {
            Directory indexDir = NewDirectory();
            Directory taxoDir = NewDirectory();

            // create and open an index writer
            RandomIndexWriter iw = new RandomIndexWriter(Random(), indexDir, NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random(), MockTokenizer.WHITESPACE, false)));
            // create and open a taxonomy writer
            var tw = new DirectoryTaxonomyWriter(taxoDir, OpenMode.CREATE);

            FacetsConfig config = Config;
            config.SetIndexFieldName("Author", "$author");
            seedIndex(tw, iw, config);

            IndexReader ir = iw.Reader;
            tw.Commit();

            // prepare index reader and taxonomy.
            var tr = new DirectoryTaxonomyReader(taxoDir);

            // prepare searcher to search against
            IndexSearcher searcher = NewSearcher(ir);

            FacetsCollector sfc = PerformSearch(tr, ir, searcher);

            IDictionary<string, Facets> facetsMap = new Dictionary<string, Facets>();
            facetsMap["Author"] = GetTaxonomyFacetCounts(tr, config, sfc, "$author");
            Facets facets = new MultiFacets(facetsMap, GetTaxonomyFacetCounts(tr, config, sfc));

            // Obtain facets results and hand-test them
            AssertCorrectResults(facets);

            assertOrdinalsExist("$facets", ir);
            assertOrdinalsExist("$author", ir);

            IOUtils.Close(tr, ir, iw, tw, indexDir, taxoDir);
        }