예제 #1
0
        /// <summary>User runs a query and aggregates facets by summing their association values.</summary>
        private IList <FacetResult> SumAssociations()
        {
            using DirectoryReader indexReader = DirectoryReader.Open(indexDir);
            using TaxonomyReader taxoReader   = new DirectoryTaxonomyReader(taxoDir);
            IndexSearcher searcher = new IndexSearcher(indexReader);

            FacetsCollector fc = new FacetsCollector();

            // MatchAllDocsQuery is for "browsing" (counts facets
            // for all non-deleted docs in the index); normally
            // you'd use a "normal" query:
            FacetsCollector.Search(searcher, new MatchAllDocsQuery(), 10, fc);

            Facets tags  = new TaxonomyFacetSumInt32Associations("$tags", taxoReader, config, fc);
            Facets genre = new TaxonomyFacetSumSingleAssociations("$genre", taxoReader, config, fc);

            // Retrieve results
            IList <FacetResult> results = new List <FacetResult>
            {
                tags.GetTopChildren(10, "tags"),
                genre.GetTopChildren(10, "genre")
            };

            return(results);
        }
예제 #2
0
        /// <summary>User drills down on 'tags/solr'.</summary>
        private FacetResult DrillDown()
        {
            using DirectoryReader indexReader = DirectoryReader.Open(indexDir);
            using TaxonomyReader taxoReader   = new DirectoryTaxonomyReader(taxoDir);
            IndexSearcher searcher = new IndexSearcher(indexReader);

            // Passing no baseQuery means we drill down on all
            // documents ("browse only"):
            DrillDownQuery q = new DrillDownQuery(config);

            // Now user drills down on Publish Date/2010:
            q.Add("tags", "solr");
            FacetsCollector fc = new FacetsCollector();

            FacetsCollector.Search(searcher, q, 10, fc);

            // Retrieve results
            Facets      facets = new TaxonomyFacetSumSingleAssociations("$genre", taxoReader, config, fc);
            FacetResult result = facets.GetTopChildren(10, "genre");

            return(result);
        }