/// <summary> /// User drills down on 'Publish Date/2010', and we /// return facets for both 'Publish Date' and 'Author', /// using DrillSideways. /// </summary> private IList <FacetResult> DrillSideways() { 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("Publish Date", "2010"); DrillSideways ds = new DrillSideways(searcher, config, taxoReader); DrillSidewaysResult result = ds.Search(q, 10); // Retrieve results IList <FacetResult> facets = result.Facets.GetAllDims(10); return(facets); }
/// <summary> /// Searches the Lucene index for Documents that match the specified search criteria. /// </summary> /// <param name="criteria">The search criteria.</param> /// <returns></returns> /// <exception cref="ArgumentNullException"></exception> /// <exception cref="System.ArgumentNullException"></exception> public SearchResult<Guid> Search(SearchCriteria criteria) { if (criteria == null) throw new ArgumentNullException(nameof(criteria)); criteria.Query = String.IsNullOrWhiteSpace(criteria.Query) ? ALL_DOCS_QUERY : criteria.Query; criteria.TopN = criteria.TopN > 0 ? criteria.TopN : SearchCriteria.DEFAULT_TOP_N; criteria.ItemsPerPage = criteria.ItemsPerPage > 0 ? criteria.ItemsPerPage : SearchCriteria.DEFAULT_ITEMS_PER_PAGE; criteria.PageNumber = criteria.PageNumber > 0 ? criteria.PageNumber : 1; criteria.Validate(); var result = new SearchResult<Guid>(criteria); var queryParser = new LuceneQueryParser(Schema.StandardField.FULL_TEXT, _compositeAnalyzer, Schema); var query = queryParser.Parse(criteria.Query); var instance = _searcherTaxonomyManager.Acquire() as SearcherTaxonomyManagerSearcherAndTaxonomy; if (instance != null) { var searcher = instance.Searcher; var taxonomyReader = instance.TaxonomyReader; try { var sort = GetSortCriteria(criteria.SortByField); var selectedFacets = criteria.SelectCategories.ToFacetFields(); var topDocs = (TopDocs)null; var categories = (IEnumerable<Category>)null; if (selectedFacets.Count() == 0) { // We are not going to do a drill-down on specific facets. // Instead we will just take the top N facets from the matching Documents. var facetsCollector = new FacetsCollector(); // Get the matching Documents topDocs = FacetsCollector.Search(searcher, query, criteria.TopN, sort, facetsCollector); // Get the Facet counts from the matching Documents var facetCounts = new FastTaxonomyFacetCounts(taxonomyReader, _facetBuilder.FacetsConfig, facetsCollector); categories = facetCounts.GetCategories(criteria.TopNCategories); } else { // Perform a drill-sideways query var drillDownQuery = new DrillDownQuery(_facetBuilder.FacetsConfig, query); foreach (var facetField in selectedFacets) drillDownQuery.Add(facetField.Dim, facetField.Path); var drillSideways = new DrillSideways(searcher, _facetBuilder.FacetsConfig, taxonomyReader); var drillSidewaysResult = drillSideways.Search(drillDownQuery, null, null, criteria.TopN, sort, false, false); // Get the matching documents topDocs = drillSidewaysResult.Hits; // Get the Facet counts from the matching Documents categories = drillSidewaysResult.Facets.GetCategories(criteria.TopNCategories, selectedFacets); } // TODO: Don't pass TopDocs; pass an IEnumerable<Guid> result.PopulateWith(topDocs, categories, id => searcher.Doc(id)); } finally { _searcherTaxonomyManager.Release(instance); searcher = null; taxonomyReader = null; } } return result; }
public SearchResult SearchForDocuments(SearchOptions searchOptions, CategoryOptions categoryOptions) { var query = ToQuery(searchOptions, categoryOptions); logger.Info("Query: '{0}'", query); var searchResults = new SearchResult(); searchResults.Matches = new List<MatchingDocument>(searchOptions.PageCount); if (CountOfIndexedFiles > 0) { using (var wrapper = mainSearchManager.Wrapper()) { DrillSideways ds = new DrillSideways(wrapper.IndexSearcher, Facets.FacetsConfig, GetTaxonomyReader()); var searchResult = ds.search( query, filter:null, after:null, topN:Math.Min(CountOfIndexedFiles, searchOptions.PageIndex + searchOptions.PageCount), sort:new Sort(CreateSortField(searchOptions.SortType)), doDocScores:false, doMaxScore:false); searchResults.TotalMatches = searchResult.hits.totalHits; if (searchResults.TotalMatches > 0) { RetrieveMatches(wrapper, searchResult.hits, searchResults.Matches, searchOptions.DoesMatch, searchOptions.PageIndex, searchOptions.PageCount); } if (categoryOptions != null && categoryOptions.FacetNames != null && categoryOptions.MaxPerCategory > 0) { searchResults.Categories = RetrieveDrilldown(searchResult.facets, categoryOptions); } } } return searchResults; }