private static long CalculateFacetCount(DocIdSet baseBitSet, DocIdSet filterDocSet) { var baseDisi = new OpenBitSetDISI(baseBitSet.Iterator(), 25000); var filterIterator = filterDocSet.Iterator(); baseDisi.InPlaceAnd(filterIterator); var total = baseDisi.Cardinality(); return(total); }
private void DoChain(OpenBitSetDISI result, Logic logic, DocIdSet dis) { if (dis is OpenBitSet) { // optimized case for OpenBitSets switch (logic) { case Logic.OR: result.Or((OpenBitSet)dis); break; case Logic.AND: result.And((OpenBitSet)dis); break; case Logic.ANDNOT: result.AndNot((OpenBitSet)dis); break; case Logic.XOR: result.Xor((OpenBitSet)dis); break; default: DoChain(result, DEFAULT, dis); break; } } else { DocIdSetIterator disi; if (dis == null) { disi = DocIdSet.EMPTY_DOCIDSET.Iterator(); } else { disi = dis.Iterator(); if (disi == null) { disi = DocIdSet.EMPTY_DOCIDSET.Iterator(); } } switch (logic) { case Logic.OR: result.InPlaceOr(disi); break; case Logic.AND: result.InPlaceAnd(disi); break; case Logic.ANDNOT: result.InPlaceNot(disi); break; case Logic.XOR: result.InPlaceXor(disi); break; default: DoChain(result, DEFAULT, dis); break; } } }
/// <summary> /// Calculates number of facets found in the filter doc set. /// </summary> /// <param name="baseBitSet">The base bit set.</param> /// <param name="filterDocSet">The filter bit set.</param> /// <returns></returns> private long CalculateFacetCount(DocIdSet baseBitSet, DocIdSet filterDocSet) { var baseDISI = new OpenBitSetDISI(baseBitSet.Iterator(), 25000); var filterIterator = filterDocSet.Iterator(); baseDISI.InPlaceAnd(filterIterator); var total = baseDISI.Cardinality(); return total; }
public IEnumerable <IHit> Query(int pageIndex, int pageSize, out int totalCount, out IEnumerable <FacetGroup> facetedResults) { totalCount = 0; facetedResults = null; if (searchPaths == null || searchPaths.Count <= 0) { searchPaths.AddRange(indexPaths.Values.Select(o => o.Path)); } List <LuceneHit> results = new List <LuceneHit>(); List <IndexSearcher> subSearchs = new List <IndexSearcher>(); searchPaths.ForEach(o => subSearchs.Add(new IndexSearcher(FSDirectory.Open(o)))); if (facetFields != null && facetFields.Count > 0) { var facetGroups = new List <FacetGroup>(); var mainQueryFilter = new CachingWrapperFilter(new QueryWrapperFilter(query)); MultiReader readers = new MultiReader(subSearchs.Select(o => o.IndexReader).ToArray()); foreach (var facetField in facetFields) { FacetGroup fg = new FacetGroup(); fg.FieldName = facetFieldNameProvider.GetMapName(TypeName, facetField); var items = new List <FacetItem>(); var allDistinctField = FieldCache_Fields.DEFAULT.GetStrings(readers, facetField).Distinct().ToArray(); int totalHits = 0; Parallel.ForEach(allDistinctField, fieldValue => { //foreach (var fieldValue in allDistinctField) //{ var facetQuery = new TermQuery(new Term(facetField, fieldValue)); var facetQueryFilter = new CachingWrapperFilter(new QueryWrapperFilter(facetQuery)); var bs = new OpenBitSetDISI(facetQueryFilter.GetDocIdSet(readers).Iterator(), readers.MaxDoc); bs.InPlaceAnd(mainQueryFilter.GetDocIdSet(readers).Iterator()); int count = (Int32)bs.Cardinality(); FacetItem item = new FacetItem(); item.GroupValue = fieldValue; item.Count = count; items.Add(item); totalHits += count; } ); fg.FacetItems = items.OrderByDescending(o => o.Count); fg.TotalHits = totalHits; facetGroups.Add(fg); } facetedResults = facetGroups.OrderBy(o => o.FieldName); } ParallelMultiSearcher searcher = new ParallelMultiSearcher(subSearchs.ToArray()); Sort sort = null; if (sortFields != null && sortFields.Count > 0) { sort = new Sort(sortFields.ToArray()); } int maxDoc = searcher.MaxDoc; int startIndex = 0; if (pageIndex >= 0 && pageSize > 0) { startIndex = pageIndex * pageSize; maxDoc = pageSize * (pageIndex + 1); } var docs = sort == null?searcher.Search(query, null, maxDoc) : searcher.Search(query, null, maxDoc, sort); totalCount = docs.TotalHits; int endIndex = docs.TotalHits - startIndex; for (int i = startIndex; i < endIndex; i++) { LuceneHit h = new LuceneHit(TypeName, DocumentBuilder, searcher.Doc(docs.ScoreDocs[i].Doc)); results.Add(h); } return(results); }