/// <summary>
 /// 
 /// </summary>
 /// <returns>A list containing BrowseFacet objects for each of the user-specified ranges</returns>
 public virtual IEnumerable<BrowseFacet> GetFacets()
 {
     if (_spec != null)
     {
         int minHitCount = _spec.MinHitCount;
         if (_ranges != null)
         {
             List<BrowseFacet> facets = new List<BrowseFacet>();
             int countIndex = -1;
             foreach (string value in _predefinedRanges)
             {
                 countIndex++;
                 if (_count.Get(countIndex) >= minHitCount)
                 {
                     BrowseFacet choice = new BrowseFacet();
                     choice.FacetValueHitCount = _count.Get(countIndex);
                     choice.Value = value;
                     facets.Add(choice);
                 }
             }
             return facets;
         }
         else
         {
             return FacetCountCollector_Fields.EMPTY_FACET_LIST;
         }
     }
     else
     {
         return FacetCountCollector_Fields.EMPTY_FACET_LIST;
     }
 }
        public virtual BrowseFacet GetFacet(string value)
        {
            if (_closed)
            {
                throw new InvalidOperationException("This instance of count collector was already closed");
            }
            int    sum        = -1;
            string foundValue = null;

            if (_list != null)
            {
                foreach (IFacetAccessible facetAccessor in _list)
                {
                    BrowseFacet facet = facetAccessor.GetFacet(value);
                    if (facet != null)
                    {
                        foundValue = facet.Value;
                        if (sum == -1)
                        {
                            sum = facet.FacetValueHitCount;
                        }
                        else
                        {
                            sum += facet.FacetValueHitCount;
                        }
                    }
                }
            }
            if (sum == -1)
            {
                return(null);
            }
            return(new BrowseFacet(foundValue, sum));
        }
Example #3
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="value">This value should be one of the user-specified ranges for this Facet Count Collector. Else an
 /// ArgumentException will be raised</param>
 /// <returns>The BrowseFacet corresponding to the range value</returns>
 public virtual BrowseFacet GetFacet(string value)
 {
     if (m_predefinedRanges != null)
     {
         int index = 0;
         if ((index = m_predefinedRanges.IndexOf(value)) != -1)
         {
             BrowseFacet choice = new BrowseFacet();
             choice.FacetValueHitCount = m_count.Get(index);
             choice.Value = value;
             return(choice);
         }
         else
         {
             // user specified an unknown range value. the overhead to calculate the count for an unknown range value is high,
             // in the sense it requires to go through each docid in the index. Till we get a better solution, this operation is
             // unsupported
             throw new ArgumentException("The value argument is not one of the user-specified ranges");
         }
     }
     else
     {
         throw new ArgumentException("There are no user-specified ranges for this Facet Count Collector object");
     }
 }
Example #4
0
 /// <summary>
 ///
 /// </summary>
 /// <returns>A list containing BrowseFacet objects for each of the user-specified ranges</returns>
 public virtual ICollection <BrowseFacet> GetFacets()
 {
     if (m_spec != null)
     {
         int minHitCount = m_spec.MinHitCount;
         if (m_ranges != null)
         {
             List <BrowseFacet> facets = new List <BrowseFacet>();
             int countIndex            = -1;
             foreach (string value in m_predefinedRanges)
             {
                 countIndex++;
                 if (m_count.Get(countIndex) >= minHitCount)
                 {
                     BrowseFacet choice = new BrowseFacet();
                     choice.FacetValueHitCount = m_count.Get(countIndex);
                     choice.Value = value;
                     facets.Add(choice);
                 }
             }
             return(facets);
         }
         else
         {
             return(FacetCountCollector.EMPTY_FACET_LIST);
         }
     }
     else
     {
         return(FacetCountCollector.EMPTY_FACET_LIST);
     }
 }
Example #5
0
        public void Test1Filter()
        {
            BrowseRequest             request = CreateRequest(1, "prop3");
            FacetCountCollectorSource facetCountCollectorSource = attributesFacetHandler.GetFacetCountCollectorSource(request.GetSelection(AttributeHandlerName), request.GetFacetSpec(AttributeHandlerName));
            RandomAccessFilter        randomAccessFilter        = attributesFacetHandler.BuildFilter(request.GetSelection(AttributeHandlerName));
            DocIdSetIterator          iterator = randomAccessFilter.GetDocIdSet(boboReader).Iterator();
            int docId = iterator.NextDoc();

            int[] docIds = new int[2];
            int   i      = 0;

            while (docId != DocIdSetIterator.NO_MORE_DOCS)
            {
                docIds[i] = docId;
                i++;
                docId = iterator.NextDoc();
            }
            Assert.AreEqual(Arrays.ToString(new int[] { 1, 2 }), Arrays.ToString(docIds));

            BrowseResult res = browser.Browse(request);

            Assert.AreEqual(res.NumHits, 2);
            IFacetAccessible          fa     = res.GetFacetAccessor(AttributeHandlerName);
            IEnumerable <BrowseFacet> facets = fa.GetFacets();

            Console.WriteLine(facets);
            Assert.AreEqual(3, facets.Count());
            BrowseFacet facet = facets.Get(0);

            Assert.AreEqual(1, facet.FacetValueHitCount);
        }
        // BoboBrowse.Net: Not supported in .NET anyway
        //public override void Remove()
        //{
        //    throw new NotSupportedException();
        //}

        public override string Next()
        {
            m_count = 0;
            BrowseFacet next = iterator.Current;

            if (next == null)
            {
                return(null);
            }
            m_count = next.FacetValueHitCount;
            m_facet = next.Value;
            return(next.Value);
        }
 public override string Next(int minHits)
 {
     while (iterator.MoveNext())
     {
         BrowseFacet next = iterator.Current;
         base.m_count = next.FacetValueHitCount;
         base.m_facet = next.Value;
         if (next.FacetValueHitCount >= minHits)
         {
             return(next.Value);
         }
     }
     return(null);
 }
            public override BrowseFacet GetFacet(string value)
            {
                string      rangeString = m_parent.BuildRangeString(value);
                BrowseFacet facet       = base.GetFacet(rangeString);

                if (facet != null)
                {
                    return(new BrowseFacet(value, facet.FacetValueHitCount));
                }
                else
                {
                    return(null);
                }
            }
 public virtual BrowseFacet GetFacet(string @value)
 {
     BrowseFacet facet = null;
     int index = _dataCache.valArray.IndexOf(@value);
     if (index >= 0)
     {
         facet = new BrowseFacet(_dataCache.valArray.Get(index), _count[index]);
     }
     else
     {
         facet = new BrowseFacet(_dataCache.valArray.Format(@value), 0);
     }
     return facet;
 }
        public virtual BrowseFacet GetFacet(string value)
        {
            BrowseFacet facet = null;
            int         index = _dataCache.ValArray.IndexOf(value);

            if (index >= 0)
            {
                facet = new BrowseFacet(_dataCache.ValArray.Get(index), _count.Get(index));
            }
            else
            {
                facet = new BrowseFacet(_dataCache.ValArray.Format(@value), 0);
            }
            return(facet);
        }
        private IEnumerable <BrowseFacet> FilterByKeys(IEnumerable <BrowseFacet> facets, char separator, int numFacetsPerKey, string[] values)
        {
            var    keyOccurences   = new Dictionary <string, AtomicInteger>();
            var    editable        = facets.ToList();
            string separatorString = Convert.ToString(separator);

            for (int i = 0; i < facets.Count(); i++)
            {
                BrowseFacet facet = facets.ElementAt(i);
                string      value = facet.Value;
                if (!value.Contains(separatorString))
                {
                    editable.Remove(facet);
                    continue;
                }

                if (values != null && values.Length > 0)
                {
                    bool belongsToKeys = false;
                    foreach (var val in values)
                    {
                        if (value.StartsWith(val))
                        {
                            belongsToKeys = true;
                            break;
                        }
                    }
                    if (!belongsToKeys)
                    {
                        editable.Remove(facet);
                        continue;
                    }
                }
                string        key       = value.Substring(0, value.IndexOf(separatorString));
                AtomicInteger numOfKeys = keyOccurences.Get(key);
                if (numOfKeys == null)
                {
                    numOfKeys = new AtomicInteger(0);
                    keyOccurences.Put(key, numOfKeys);
                }
                int count = numOfKeys.IncrementAndGet();
                if (count > numFacetsPerKey)
                {
                    editable.Remove(facet);
                }
            }
            return(editable);
        }
        public virtual BrowseFacet GetFacet(string value)
        {
            BrowseFacet facet = null;

            int[] range = FacetRangeFilter.Parse(_dataCache, value);
            if (range != null)
            {
                int sum = 0;
                for (int i = range[0]; i <= range[1]; ++i)
                {
                    sum += _count.Get(i);
                }
                facet = new BrowseFacet(value, sum);
            }
            return(facet);
        }
Example #13
0
        public virtual ICollection <BrowseFacet> GetFacets()
        {
            if (m_ospec != null)
            {
                if (m_predefinedRangeIndexes != null)
                {
                    int minCount = m_ospec.MinHitCount;
                    //int maxNumOfFacets = _ospec.getMaxCount();
                    //if (maxNumOfFacets <= 0 || maxNumOfFacets > _predefinedRangeIndexes.length)
                    //    maxNumOfFacets = _predefinedRangeIndexes.length;

                    int[] rangeCount = new int[m_predefinedRangeIndexes.Length];
                    for (int k = 0; k < m_predefinedRangeIndexes.Length; ++k)
                    {
                        int count = 0;
                        int idx   = m_predefinedRangeIndexes[k][0];
                        int end   = m_predefinedRangeIndexes[k][1];
                        while (idx < end)
                        {
                            count += m_count.Get(idx++);
                        }
                        rangeCount[k] = count;
                    }

                    List <BrowseFacet> facetColl = new List <BrowseFacet>(m_predefinedRanges.Count);
                    for (int k = 0; k < m_predefinedRanges.Count; ++k)
                    {
                        if (rangeCount[k] >= minCount)
                        {
                            BrowseFacet choice = new BrowseFacet(m_predefinedRanges[k], rangeCount[k]);
                            facetColl.Add(choice);
                        }
                        //if(facetColl.size() >= maxNumOfFacets) break;
                    }
                    return(facetColl);
                }
                else
                {
                    return(FacetCountCollector.EMPTY_FACET_LIST);
                }
            }
            else
            {
                return(FacetCountCollector.EMPTY_FACET_LIST);
            }
        }
 /// <summary>
 /// (non-Javadoc)
 /// see com.browseengine.bobo.api.FacetAccessible#getFacets()
 /// </summary>
 /// <returns></returns>
 public virtual IEnumerable <BrowseFacet> GetFacets()
 {
     if (_spec != null)
     {
         if (_latPredefinedRangeIndexes != null)
         {
             int   minCount    = _spec.MinHitCount;
             int[] rangeCounts = new int[_latPredefinedRangeIndexes.Length];
             for (int i = 0; i < _latCount.Length; ++i)
             {
                 if (_latCount[i] > 0)
                 {
                     for (int k = 0; k < _latPredefinedRangeIndexes.Length; ++k)
                     {
                         if (i >= _latPredefinedRangeIndexes[k][0] && i <= _latPredefinedRangeIndexes[k][1])
                         {
                             rangeCounts[k] += _latCount[i];
                         }
                     }
                 }
             }
             List <BrowseFacet> list = new List <BrowseFacet>(rangeCounts.Length);
             for (int i = 0; i < rangeCounts.Length; ++i)
             {
                 if (rangeCounts[i] >= minCount)
                 {
                     BrowseFacet choice = new BrowseFacet();
                     choice.FacetValueHitCount = rangeCounts[i];
                     choice.Value = _predefinedRanges.Get(i);
                     list.Add(choice);
                 }
             }
             return(list);
         }
         else
         {
             return(FacetCountCollector_Fields.EMPTY_FACET_LIST);
         }
     }
     else
     {
         return(FacetCountCollector_Fields.EMPTY_FACET_LIST);
     }
 }
Example #15
0
        public virtual BrowseFacet GetFacet(string value)
        {
            if (m_closed)
            {
                throw new InvalidOperationException("This instance of count collector for " + m_name + " was already closed");
            }
            BrowseFacet facet = null;
            int         index = m_dataCache.ValArray.IndexOf(value);

            if (index >= 0)
            {
                facet = new BrowseFacet(m_dataCache.ValArray.Get(index), m_count.Get(index));
            }
            else
            {
                facet = new BrowseFacet(m_dataCache.ValArray.Format(@value), 0);
            }
            return(facet);
        }
            public override ICollection <BrowseFacet> GetFacets()
            {
                IEnumerable <BrowseFacet> list    = base.GetFacets();
                List <BrowseFacet>        retList = new List <BrowseFacet>();
                IEnumerator <BrowseFacet> iter    = list.GetEnumerator();

                while (iter.MoveNext())
                {
                    BrowseFacet facet       = iter.Current;
                    string      val         = facet.Value;
                    string      rangeString = m_parent.GetValueFromRangeString(val);
                    if (rangeString != null)
                    {
                        BrowseFacet convertedFacet = new BrowseFacet(rangeString, facet.FacetValueHitCount);
                        retList.Add(convertedFacet);
                    }
                }
                return(retList);
            }
            public virtual ICollection <BrowseFacet> GetFacets()
            {
                if (m_ospec != null)
                {
                    int minCount = m_ospec.MinHitCount;
                    int max      = m_ospec.MaxCount;
                    if (max <= 0)
                    {
                        max = m_count.Length;
                    }

                    List <BrowseFacet>      facetColl;
                    FacetSpec.FacetSortSpec sortspec = m_ospec.OrderBy;
                    if (sortspec == FacetSpec.FacetSortSpec.OrderValueAsc)
                    {
                        facetColl = new List <BrowseFacet>(max);
                        for (int i = 0; i < m_count.Length; ++i)
                        {
                            int hits = m_count.Get(i);
                            if (hits >= minCount)
                            {
                                BrowseFacet facet = new BrowseFacet(i.ToString(NUMBER_FORMAT), hits);
                                facetColl.Add(facet);
                            }
                            if (facetColl.Count >= max)
                            {
                                break;
                            }
                        }
                        return(facetColl);
                    }
                    else
                    {
                        return(FacetCountCollector.EMPTY_FACET_LIST);
                    }
                }
                else
                {
                    return(FacetCountCollector.EMPTY_FACET_LIST);
                }
            }
        public virtual FacetIterator GetIterator()
        {
            IDictionary <string, string> props = m_sel == null ? null : m_sel.SelectionProperties;
            int  depth  = PathFacetHandler.GetDepth(props);
            bool strict = PathFacetHandler.IsStrict(props);
            List <BrowseFacet> finalList;

            string[] paths = m_sel == null ? null : m_sel.Values;
            if (paths == null || paths.Length == 0)
            {
                finalList = new List <BrowseFacet>(GetFacetsForPath(null, depth, strict, int.MinValue, m_count.Length));
                return(new PathFacetIterator(finalList));
            }

            if (paths.Length == 1)
            {
                finalList = new List <BrowseFacet>(GetFacetsForPath(paths[0], depth, strict, int.MinValue, m_count.Length));
                return(new PathFacetIterator(finalList));
            }

            finalList = new List <BrowseFacet>();
            var iterList = new List <IEnumerator <BrowseFacet> >(paths.Length);

            foreach (string path in paths)
            {
                var subList = GetFacetsForPath(path, depth, strict, int.MinValue, m_count.Length);
                if (subList.Count > 0)
                {
                    iterList.Add(subList.GetEnumerator());
                }
            }
            var finalIter = ListMerger.MergeLists(iterList.ToArray(),
                                                  m_comparerFactory == null ? new FacetValueComparerFactory().NewComparer() : m_comparerFactory.NewComparer());

            while (finalIter.MoveNext())
            {
                BrowseFacet f = finalIter.Current;
                finalList.Add(f);
            }
            return(new PathFacetIterator(finalList));
        }
        public virtual IEnumerable <BrowseFacet> GetFacets()
        {
            IDictionary <string, string> props = _sel == null ? null : _sel.SelectionProperties;
            int  depth  = PathFacetHandler.GetDepth(props);
            bool strict = PathFacetHandler.IsStrict(props);

            string[] paths = _sel == null ? null : _sel.Values;
            if (paths == null || paths.Length == 0)
            {
                return(GetFacetsForPath(null, depth, strict, _minHitCount, _maxCount));
            }

            if (paths.Length == 1)
            {
                return(GetFacetsForPath(paths[0], depth, strict, _minHitCount, _maxCount));
            }

            List <BrowseFacet> finalList = new List <BrowseFacet>();
            var iterList = new List <IEnumerator <BrowseFacet> >(paths.Length);

            foreach (string path in paths)
            {
                var subList = GetFacetsForPath(path, depth, strict, _minHitCount, _maxCount);
                if (subList.Count() > 0)
                {
                    iterList.Add(subList.GetEnumerator());
                }
            }

            var finalIter = ListMerger.MergeLists(iterList.ToArray(),
                                                  _comparatorFactory == null ? new FacetValueComparatorFactory().NewComparator() : _comparatorFactory.NewComparator());

            while (finalIter.MoveNext())
            {
                BrowseFacet f = finalIter.Current;
                finalList.Insert(0, f);
            }
            return(finalList);
        }
            public virtual BrowseFacet GetFacet(string value)
            {
                string[] vals = value.Split(new string[] { m_sep }, StringSplitOptions.RemoveEmptyEntries);
                if (vals.Length == 0)
                {
                    return(null);
                }
                StringBuilder buf      = new StringBuilder();
                int           startIdx = 0;
                int           segLen   = m_countlength;

                for (int i = 0; i < vals.Length; ++i)
                {
                    if (i > 0)
                    {
                        buf.Append(m_sep);
                    }
                    int    index     = m_subcollectors[i].DataCache.ValArray.IndexOf(vals[i]);
                    string facetName = m_subcollectors[i].DataCache.ValArray.Get(index);
                    buf.Append(facetName);

                    segLen   /= m_subcollectors[i].CountLength;
                    startIdx += index * segLen;
                }

                int count = 0;

                for (int i = startIdx; i < startIdx + segLen; ++i)
                {
                    count += m_count.Get(i);
                }

                BrowseFacet f = new BrowseFacet(buf.ToString(), count);

                return(f);
            }
 /// <summary>
 /// 
 /// </summary>
 /// <param name="value">This value should be one of the user-specified ranges for this Facet Count Collector. Else an
 /// ArgumentException will be raised</param>
 /// <returns>The BrowseFacet corresponding to the range value</returns>
 public virtual BrowseFacet GetFacet(string value)
 {
     if (_predefinedRanges != null)
     {
         int index = 0;
         if ((index = _predefinedRanges.IndexOf(value)) != -1)
         {
             BrowseFacet choice = new BrowseFacet();
             choice.FacetValueHitCount = _count.Get(index);
             choice.Value = value;
             return choice;
         }
         else
         {
             // user specified an unknown range value. the overhead to calculate the count for an unknown range value is high,
             // in the sense it requires to go through each docid in the index. Till we get a better solution, this operation is
             // unsupported
             throw new ArgumentException("The value argument is not one of the user-specified ranges");
         }
     }
     else
     {
         throw new ArgumentException("There are no user-specified ranges for this Facet Count Collector object");
     }
 }
            private IEnumerable<BrowseFacet> getFacetsForPath(string selectedPath, int depth, bool strict, int minCount)
            {
                LinkedList<BrowseFacet> list = new LinkedList<BrowseFacet>();

                string[] startParts = null;
                int startDepth = 0;

                if (selectedPath != null && selectedPath.Length > 0)
                {
                    startParts = selectedPath.Split(new string[] { _sep }, StringSplitOptions.RemoveEmptyEntries);
                    startDepth = startParts.Length;
                    if (!selectedPath.EndsWith(_sep))
                    {
                        selectedPath += _sep;
                    }
                }

                string currentPath = null;
                int currentCount = 0;

                int wantedDepth = startDepth + depth;

                int index = 0;
                if (selectedPath != null && selectedPath.Length > 0)
                {
                    index = _dataCache.valArray.IndexOf(selectedPath);
                    if (index < 0)
                    {
                        index = -(index + 1);
                    }
                }

                for (int i = index; i < _count.Length; ++i)
                {
                    if (_count[i] >= minCount)
                    {
                        string path = _dataCache.valArray.Get(i);
                        //if (path==null || path.equals(selectedPath)) continue;						

                        int subCount = _count[i];

                        string[] pathParts = path.Split(new string[] { _sep }, StringSplitOptions.RemoveEmptyEntries);

                        int pathDepth = pathParts.Length;

                        if ((startDepth == 0) || (startDepth > 0 && path.StartsWith(selectedPath)))
                        {
                            StringBuilder buf = new StringBuilder();
                            int minDepth = Math.Min(wantedDepth, pathDepth);
                            for (int k = 0; k < minDepth; ++k)
                            {
                                buf.Append(pathParts[k]);
                                if (!pathParts[k].EndsWith(_sep))
                                {
                                    if (pathDepth != wantedDepth || k < (wantedDepth - 1))
                                        buf.Append(_sep);
                                }
                            }
                            string wantedPath = buf.ToString();
                            if (currentPath == null)
                            {
                                currentPath = wantedPath;
                                currentCount = subCount;
                            }
                            else if (wantedPath.Equals(currentPath))
                            {
                                if (!strict)
                                {
                                    currentCount += subCount;
                                }
                            }
                            else
                            {
                                bool directNode = false;

                                if (wantedPath.EndsWith(_sep))
                                {
                                    if (currentPath.Equals(wantedPath.Substring(0, wantedPath.Length - 1)))
                                    {
                                        directNode = true;
                                    }
                                }

                                if (strict)
                                {
                                    if (directNode)
                                    {
                                        currentCount += subCount;
                                    }
                                    else
                                    {
                                        BrowseFacet ch = new BrowseFacet(currentPath, currentCount);
                                        list.AddLast(ch);
                                        currentPath = wantedPath;
                                        currentCount = subCount;
                                    }
                                }
                                else
                                {
                                    if (!directNode)
                                    {
                                        BrowseFacet ch = new BrowseFacet(currentPath, currentCount);
                                        list.AddLast(ch);
                                        currentPath = wantedPath;
                                        currentCount = subCount;
                                    }
                                    else
                                    {
                                        currentCount += subCount;
                                    }
                                }
                            }
                        }
                        else
                        {
                            break;
                        }
                    }
                }

                if (currentPath != null && currentCount > 0)
                {
                    list.AddLast(new BrowseFacet(currentPath, currentCount));
                }

                return list;
            }
        public virtual List <BrowseFacet> GetFacetsNew()
        {
            if (_ospec != null)
            {
                if (_predefinedRangeIndexes != null)
                {
                    int minCount       = _ospec.MinHitCount;
                    int maxNumOfFacets = _ospec.MaxCount;
                    if (maxNumOfFacets <= 0 || maxNumOfFacets > _predefinedRangeIndexes.Length)
                    {
                        maxNumOfFacets = _predefinedRangeIndexes.Length;
                    }

                    BigSegmentedArray rangeCount = new LazyBigIntArray(_predefinedRangeIndexes.Length);

                    for (int k = 0; k < _predefinedRangeIndexes.Length; ++k)
                    {
                        int count = 0;
                        int idx   = _predefinedRangeIndexes[k][0];
                        int end   = _predefinedRangeIndexes[k][1];
                        while (idx <= end)
                        {
                            count += _count.Get(idx++);
                        }
                        rangeCount.Add(k, count);
                    }

                    List <BrowseFacet>      facetColl;
                    FacetSpec.FacetSortSpec sortspec = _ospec.OrderBy;
                    if (sortspec == FacetSpec.FacetSortSpec.OrderValueAsc)
                    {
                        facetColl = new List <BrowseFacet>(maxNumOfFacets);
                        for (int k = 0; k < _predefinedRangeIndexes.Length; ++k)
                        {
                            if (rangeCount.Get(k) >= minCount)
                            {
                                BrowseFacet choice = new BrowseFacet(_predefinedRanges.Get(k), rangeCount.Get(k));
                                facetColl.Add(choice);
                            }
                            if (facetColl.Count >= maxNumOfFacets)
                            {
                                break;
                            }
                        }
                    }
                    else //if (sortspec == FacetSortSpec.OrderHitsDesc)
                    {
                        IComparatorFactory comparatorFactory;
                        if (sortspec == FacetSpec.FacetSortSpec.OrderHitsDesc)
                        {
                            comparatorFactory = new FacetHitcountComparatorFactory();
                        }
                        else
                        {
                            comparatorFactory = _ospec.CustomComparatorFactory;
                        }

                        if (comparatorFactory == null)
                        {
                            throw new ArgumentException("facet comparator factory not specified");
                        }

                        IComparer <int> comparator = comparatorFactory.NewComparator(new RangeFacetCountCollectorFieldAccessor(_predefinedRanges), rangeCount);

                        int forbidden = -1;
                        IntBoundedPriorityQueue pq = new IntBoundedPriorityQueue(comparator, maxNumOfFacets, forbidden);
                        for (int i = 0; i < _predefinedRangeIndexes.Length; ++i)
                        {
                            if (rangeCount.Get(i) >= minCount)
                            {
                                pq.Offer(i);
                            }
                        }

                        int val;
                        facetColl = new List <BrowseFacet>();
                        while ((val = pq.Poll()) != forbidden)
                        {
                            BrowseFacet facet = new BrowseFacet(_predefinedRanges.ElementAt(val), rangeCount.Get(val));
                            facetColl.Insert(0, facet);
                        }
                    }
                    return(facetColl);
                }
                else
                {
                    return(FacetCountCollector_Fields.EMPTY_FACET_LIST);
                }
            }
            else
            {
                return(FacetCountCollector_Fields.EMPTY_FACET_LIST);
            }
        }
 public virtual List<BrowseFacet> combine(BrowseFacet facet, List<BrowseFacet> facets)
 {
     // TODO Auto-generated method stub
     return null;
 }
 internal virtual void ConvertFacets(BrowseFacet[] facets)
 {
     int i = 0;
     foreach (BrowseFacet facet in facets)
     {
         int hit = facet.HitCount;
         object val = facet.Value;
         RangeFacet rangeFacet = new RangeFacet();
         rangeFacet.SetValues(val, val);
         rangeFacet.HitCount = hit;
         facets[i++] = rangeFacet;
     }
 }
 public virtual IEnumerable<BrowseFacet> GetFacets()
 {
     if (ospec != null)
     {
         if (autoRange)
         {
             return BuildDynamicRanges();
         }
         else
         {
             if (predefinedRangeIndexes != null)
             {
                 int minCount = ospec.MinHitCount;
                 int[] rangeCounts = new int[predefinedRangeIndexes.Length];
                 for (int i = 0; i < count.Length; ++i)
                 {
                     if (count[i] > 0)
                     {
                         for (int k = 0; k < predefinedRangeIndexes.Length; ++k)
                         {
                             if (i >= predefinedRangeIndexes[k][0] && i <= predefinedRangeIndexes[k][1])
                             {
                                 rangeCounts[k] += count[i];
                             }
                         }
                     }
                 }
                 List<BrowseFacet> list = new List<BrowseFacet>(rangeCounts.Length);
                 for (int i = 0; i < rangeCounts.Length; ++i)
                 {
                     if (rangeCounts[i] >= minCount)
                     {
                         BrowseFacet choice = new BrowseFacet();
                         choice.HitCount = rangeCounts[i];
                         choice.Value = predefinedRanges.ElementAt(i);
                         list.Add(choice);
                     }
                 }
                 return list;
             }
             else
             {
                 return IFacetCountCollector_Fields.EMPTY_FACET_LIST;
             }
         }
     }
     else
     {
         return IFacetCountCollector_Fields.EMPTY_FACET_LIST;
     }
 }
        public virtual IEnumerable<BrowseFacet> GetFacets()
        {
            if (_ospec != null)
            {
                if (_predefinedRangeIndexes != null)
                {
                    int minCount = _ospec.MinHitCount;
                    //int maxNumOfFacets = _ospec.getMaxCount();
                    //if (maxNumOfFacets <= 0 || maxNumOfFacets > _predefinedRangeIndexes.length) maxNumOfFacets = _predefinedRangeIndexes.length;

                    int[] rangeCount = new int[_predefinedRangeIndexes.Length];
                    for (int k = 0; k < _predefinedRangeIndexes.Length; ++k)
                    {
                        int count = 0;
                        int idx = _predefinedRangeIndexes[k][0];
                        int end = _predefinedRangeIndexes[k][1];
                        while (idx < end)
                        {
                            count += _count.Get(idx++);
                        }
                        rangeCount[k] = count;
                    }

                    List<BrowseFacet> facetColl = new List<BrowseFacet>(_predefinedRanges.Count());
                    for (int k = 0; k < _predefinedRanges.Count(); ++k)
                    {
                        if (rangeCount[k] >= minCount)
                        {
                            BrowseFacet choice = new BrowseFacet(_predefinedRanges.ElementAt(k), rangeCount[k]);
                            facetColl.Add(choice);
                        }
                        //if(facetColl.size() >= maxNumOfFacets) break;
                    }
                    return facetColl;
                }
                else
                {
                    return FacetCountCollector_Fields.EMPTY_FACET_LIST;
                }
            }
            else
            {
                return FacetCountCollector_Fields.EMPTY_FACET_LIST;
            }
        }
        public virtual IEnumerable<BrowseFacet> GetFacets()
        {
            if (_ospec != null)
            {
                string facetPrefix = _ospec.Prefix;
                bool checkPrefix = !string.IsNullOrEmpty(facetPrefix);

                int minCount = _ospec.MinHitCount;
                int max = _ospec.MaxCount;
                if (max <= 0)
                {
                    max = _count.Length;
                }

                ICollection<BrowseFacet> facetColl;
                List<string> valList = _dataCache.valArray.GetInnerList();
                FacetSpec.FacetSortSpec sortspec = _ospec.OrderBy;
                if (sortspec == FacetSpec.FacetSortSpec.OrderValueAsc)
                {
                    facetColl = new List<BrowseFacet>(max);
                    for (int i = 1; i < _count.Length; ++i) // exclude zero
                    {
                        int hits = _count[i];
                        if (!checkPrefix || valList[i].StartsWith(facetPrefix))
                        {
                            if (hits >= minCount)
                            {
                                BrowseFacet facet = new BrowseFacet(valList[i], hits);
                                facetColl.Add(facet);
                            }
                        }
                        if (facetColl.Count >= max)
                            break;
                    }
                }
                else //if (sortspec == FacetSortSpec.OrderHitsDesc)
                {
                    IComparatorFactory comparatorFactory;
                    if (sortspec == FacetSpec.FacetSortSpec.OrderHitsDesc)
                    {
                        comparatorFactory = new FacetHitcountComparatorFactory();
                    }
                    else
                    {
                        comparatorFactory = _ospec.CustomComparatorFactory;
                    }

                    if (comparatorFactory == null)
                    {
                        throw new System.ArgumentException("facet comparator factory not specified");
                    }

                    IComparer<int> comparator = comparatorFactory.NewComparator(new DefaultFacetCountCollectorFieldAccessor(_dataCache), _count);
                    facetColl = new LinkedList<BrowseFacet>();
                    BoundedPriorityQueue<int> pq = new BoundedPriorityQueue<int>(comparator, max);

                    for (int i = 1; i < _count.Length; ++i) // exclude zero
                    {
                        int hits = _count[i];
                        if (hits >= minCount)
                        {
                            if (!checkPrefix || valList[i].StartsWith(facetPrefix))
                            {
                                if (!pq.Offer(i))
                                {
                                    // pq is full. we can safely ignore any facet with <=hits.
                                    minCount = hits + 1;
                                }
                            }
                        }
                    }

                    while (!pq.IsEmpty)
                    {
                        int val = pq.DeleteMax();
                        BrowseFacet facet = new BrowseFacet(valList[val], _count[val]);
                        facetColl.Add(facet);
                    }
                }
                return facetColl;
            }
            else
            {
                return IFacetCountCollector_Fields.EMPTY_FACET_LIST;
            }
        }
 public virtual BrowseFacet GetFacet(string value)
 {
     BrowseFacet facet = null;
     int[] range = FacetRangeFilter.Parse(_dataCache, value);
     if (range != null)
     {
         int sum = 0;
         for (int i = range[0]; i <= range[1]; ++i)
         {
             sum += _count.Get(i);
         }
         facet = new BrowseFacet(value, sum);
     }
     return facet;
 }
 /// <summary>
 /// 
 /// </summary>
 /// <remarks>
 /// This method was internal in the original design, but made it
 /// protected to make it easy to bring back the auto ranges feature if so desired.
 /// </remarks>
 /// <param name="facets"></param>
 protected virtual void ConvertFacets(BrowseFacet[] facets)
 {
     int i = 0;
     foreach (BrowseFacet facet in facets)
     {
         int hit = facet.FacetValueHitCount;
         string val = facet.Value;
         RangeFacet rangeFacet = new RangeFacet();
         rangeFacet.SetValues(val, val);
         rangeFacet.FacetValueHitCount = hit;
         facets[i++] = rangeFacet;
     }
 }
 /// <summary>
 /// 
 /// </summary>
 /// <returns>A list containing BrowseFacet objects for each of the user-specified ranges</returns>
 public virtual IEnumerable<BrowseFacet> GetFacets()
 {
     if (_spec != null)
     {
         int minHitCount = _spec.MinHitCount;
         if (_ranges != null)
         {
             List<BrowseFacet> facets = new List<BrowseFacet>();
             int countIndex = -1;
             foreach (string value in _predefinedRanges)
             {
                 countIndex++;
                 if (_count.Get(countIndex) >= minHitCount)
                 {
                     BrowseFacet choice = new BrowseFacet();
                     choice.FacetValueHitCount = _count.Get(countIndex);
                     choice.Value = value;
                     facets.Add(choice);
                 }
             }
             return facets;
         }
         else
         {
             return FacetCountCollector_Fields.EMPTY_FACET_LIST;
         }
     }
     else
     {
         return FacetCountCollector_Fields.EMPTY_FACET_LIST;
     }
 }
        private ICollection <BrowseFacet> GetFacetsForPath(string selectedPath, int depth, bool strict, int minCount, int maxCount)
        {
            List <BrowseFacet> list = new List <BrowseFacet>();

            BoundedPriorityQueue <BrowseFacet> pq = null;

            if (m_comparerFactory != null)
            {
                IComparer <BrowseFacet> comparer = m_comparerFactory.NewComparer();

                pq = new BoundedPriorityQueue <BrowseFacet>(new PathFacetCountCollectorComparer(comparer), maxCount);
            }

            string[] startParts = null;
            int      startDepth = 0;

            if (selectedPath != null && selectedPath.Length > 0)
            {
                startParts = selectedPath.Split(new string[] { m_sep }, StringSplitOptions.RemoveEmptyEntries);
                startDepth = startParts.Length;
                if (!selectedPath.EndsWith(m_sep))
                {
                    selectedPath += m_sep;
                }
            }

            string currentPath  = null;
            int    currentCount = 0;

            int wantedDepth = startDepth + depth;

            int index = 0;

            if (selectedPath != null && selectedPath.Length > 0)
            {
                index = m_dataCache.ValArray.IndexOf(selectedPath);
                if (index < 0)
                {
                    index = -(index + 1);
                }
            }

            StringBuilder buf = new StringBuilder();

            for (int i = index; i < m_count.Length; ++i)
            {
                if (m_count.Get(i) >= minCount)
                {
                    string path = m_dataCache.ValArray.Get(i);
                    //if (path==null || path.equals(selectedPath)) continue;

                    int subCount = m_count.Get(i);

                    // do not use Java split string in a loop !
                    //				string[] pathParts=path.split(_sep);
                    int pathDepth = 0;
                    if (!SplitString(path))
                    {
                        pathDepth = 0;
                    }
                    else
                    {
                        pathDepth = PatListSize();
                    }

                    int tmpdepth = 0;
                    if ((startDepth == 0) || (startDepth > 0 && path.StartsWith(selectedPath)))
                    {
                        buf = new StringBuilder();

                        int minDepth = Math.Min(wantedDepth, pathDepth);
                        tmpdepth = 0;
                        for (int k = m_patStart; ((k < m_patEnd) && (tmpdepth < minDepth)); ++k, tmpdepth++)
                        {
                            buf.Append(m_stringData[k]);
                            if (!m_stringData[k].EndsWith(m_sep))
                            {
                                if (pathDepth != wantedDepth || k < (wantedDepth - 1))
                                {
                                    buf.Append(m_sep);
                                }
                            }
                        }
                        string wantedPath = buf.ToString();
                        if (currentPath == null)
                        {
                            currentPath  = wantedPath;
                            currentCount = subCount;
                        }
                        else if (wantedPath.Equals(currentPath))
                        {
                            if (!strict)
                            {
                                currentCount += subCount;
                            }
                        }
                        else
                        {
                            bool directNode = false;

                            if (wantedPath.EndsWith(m_sep))
                            {
                                if (currentPath.Equals(wantedPath.Substring(0, wantedPath.Length - 1)))
                                {
                                    directNode = true;
                                }
                            }

                            if (strict)
                            {
                                if (directNode)
                                {
                                    currentCount += subCount;
                                }
                                else
                                {
                                    BrowseFacet ch = new BrowseFacet(currentPath, currentCount);
                                    if (pq != null)
                                    {
                                        pq.Add(ch);
                                    }
                                    else
                                    {
                                        if (list.Count < maxCount)
                                        {
                                            list.Add(ch);
                                        }
                                    }
                                    currentPath  = wantedPath;
                                    currentCount = subCount;
                                }
                            }
                            else
                            {
                                if (!directNode)
                                {
                                    BrowseFacet ch = new BrowseFacet(currentPath, currentCount);
                                    if (pq != null)
                                    {
                                        pq.Add(ch);
                                    }
                                    else
                                    {
                                        if (list.Count < maxCount)
                                        {
                                            list.Add(ch);
                                        }
                                    }
                                    currentPath  = wantedPath;
                                    currentCount = subCount;
                                }
                                else
                                {
                                    currentCount += subCount;
                                }
                            }
                        }
                    }
                    else
                    {
                        break;
                    }
                }
            }

            if (currentPath != null && currentCount > 0)
            {
                BrowseFacet ch = new BrowseFacet(currentPath, currentCount);
                if (pq != null)
                {
                    pq.Add(ch);
                }
                else
                {
                    if (list.Count < maxCount)
                    {
                        list.Add(ch);
                    }
                }
            }

            if (pq != null)
            {
                BrowseFacet val;
                while ((val = pq.Poll()) != null)
                {
                    list.Insert(0, val);
                }
            }

            return(list);
        }
            public virtual ICollection <BrowseFacet> GetFacets()
            {
                if (m_fspec != null)
                {
                    int minCount = m_fspec.MinHitCount;
                    int max      = m_fspec.MaxCount;
                    if (max <= 0)
                    {
                        max = m_countlength;
                    }

                    FacetSpec.FacetSortSpec sortspec = m_fspec.OrderBy;
                    List <BrowseFacet>      facetColl;
                    if (sortspec == FacetSpec.FacetSortSpec.OrderValueAsc)
                    {
                        facetColl = new List <BrowseFacet>(max);
                        for (int i = 1; i < m_countlength; ++i) // exclude zero
                        {
                            int hits = m_count.Get(i);
                            if (hits >= minCount)
                            {
                                BrowseFacet facet = new BrowseFacet(GetFacetString(i), hits);
                                facetColl.Add(facet);
                            }
                            if (facetColl.Count >= max)
                            {
                                break;
                            }
                        }
                    }
                    else
                    {
                        IComparerFactory comparerFactory;
                        if (sortspec == FacetSpec.FacetSortSpec.OrderHitsDesc)
                        {
                            comparerFactory = new FacetHitcountComparerFactory();
                        }
                        else
                        {
                            comparerFactory = m_fspec.CustomComparerFactory;
                        }

                        if (comparerFactory == null)
                        {
                            throw new System.ArgumentException("facet comparer factory not specified");
                        }

                        IComparer <int> comparer = comparerFactory.NewComparer(new GroupbyFieldValueAccessor(this.GetFacetString, this.GetRawFaceValue), m_count);
                        facetColl = new List <BrowseFacet>();
                        int forbidden = -1;
                        Int32BoundedPriorityQueue pq = new Int32BoundedPriorityQueue(comparer, max, forbidden);

                        for (int i = 1; i < m_countlength; ++i) // exclude zero
                        {
                            int hits = m_count.Get(i);
                            if (hits >= minCount)
                            {
                                if (!pq.Offer(i))
                                {
                                    // pq is full. we can safely ignore any facet with <=hits.
                                    minCount = hits + 1;
                                }
                            }
                        }

                        int val;
                        while ((val = pq.Poll()) != forbidden)
                        {
                            BrowseFacet facet = new BrowseFacet(GetFacetString(val), m_count.Get(val));
                            facetColl.Insert(0, facet);
                        }
                    }
                    return(facetColl);
                }
                else
                {
                    return(FacetCountCollector.EMPTY_FACET_LIST);
                }
            }
 /// <summary>
 /// (non-Javadoc)
 /// see com.browseengine.bobo.api.FacetAccessible#getFacets()
 /// </summary>
 /// <returns></returns>
 public virtual IEnumerable<BrowseFacet> GetFacets()
 {
     if (_spec != null)
     {
         if (_latPredefinedRangeIndexes != null)
         {
             int minCount = _spec.MinHitCount;
             int[] rangeCounts = new int[_latPredefinedRangeIndexes.Length];
             for (int i = 0; i < _latCount.Length; ++i)
             {
                 if (_latCount[i] > 0)
                 {
                     for (int k = 0; k < _latPredefinedRangeIndexes.Length; ++k)
                     {
                         if (i >= _latPredefinedRangeIndexes[k][0] && i <= _latPredefinedRangeIndexes[k][1])
                         {
                             rangeCounts[k] += _latCount[i];
                         }
                     }
                 }
             }
             List<BrowseFacet> list = new List<BrowseFacet>(rangeCounts.Length);
             for (int i = 0; i < rangeCounts.Length; ++i)
             {
                 if (rangeCounts[i] >= minCount)
                 {
                     BrowseFacet choice = new BrowseFacet();
                     choice.FacetValueHitCount = rangeCounts[i];
                     choice.Value = _predefinedRanges.Get(i);
                     list.Add(choice);
                 }
             }
             return list;
         }
         else
         {
             return FacetCountCollector_Fields.EMPTY_FACET_LIST;
         }
     }
     else
     {
         return FacetCountCollector_Fields.EMPTY_FACET_LIST;
     }
 }
        public virtual List<BrowseFacet> GetFacetsNew()
        {
            if (_ospec != null)
            {
                if (_predefinedRangeIndexes != null)
                {
                    int minCount = _ospec.MinHitCount;
                    int maxNumOfFacets = _ospec.MaxCount;
                    if (maxNumOfFacets <= 0 || maxNumOfFacets > _predefinedRangeIndexes.Length) maxNumOfFacets = _predefinedRangeIndexes.Length;

                    BigSegmentedArray rangeCount = new LazyBigIntArray(_predefinedRangeIndexes.Length);

                    for (int k = 0; k < _predefinedRangeIndexes.Length; ++k)
                    {
                        int count = 0;
                        int idx = _predefinedRangeIndexes[k][0];
                        int end = _predefinedRangeIndexes[k][1];
                        while (idx <= end)
                        {
                            count += _count.Get(idx++);
                        }
                        rangeCount.Add(k, count);
                    }

                    List<BrowseFacet> facetColl;
                    FacetSpec.FacetSortSpec sortspec = _ospec.OrderBy;
                    if (sortspec == FacetSpec.FacetSortSpec.OrderValueAsc)
                    {
                        facetColl = new List<BrowseFacet>(maxNumOfFacets);
                        for (int k = 0; k < _predefinedRangeIndexes.Length; ++k)
                        {
                            if (rangeCount.Get(k) >= minCount)
                            {
                                BrowseFacet choice = new BrowseFacet(_predefinedRanges.Get(k), rangeCount.Get(k));
                                facetColl.Add(choice);
                            }
                            if (facetColl.Count >= maxNumOfFacets) break;
                        }
                    }
                    else //if (sortspec == FacetSortSpec.OrderHitsDesc)
                    {
                        IComparatorFactory comparatorFactory;
                        if (sortspec == FacetSpec.FacetSortSpec.OrderHitsDesc)
                        {
                            comparatorFactory = new FacetHitcountComparatorFactory();
                        }
                        else
                        {
                            comparatorFactory = _ospec.CustomComparatorFactory;
                        }

                        if (comparatorFactory == null)
                        {
                            throw new ArgumentException("facet comparator factory not specified");
                        }

                        IComparer<int> comparator = comparatorFactory.NewComparator(new RangeFacetCountCollectorFieldAccessor(_predefinedRanges), rangeCount);

                        int forbidden = -1;
                        IntBoundedPriorityQueue pq = new IntBoundedPriorityQueue(comparator, maxNumOfFacets, forbidden);
                        for (int i = 0; i < _predefinedRangeIndexes.Length; ++i)
                        {
                            if (rangeCount.Get(i) >= minCount) pq.Offer(i);
                        }

                        int val;
                        facetColl = new List<BrowseFacet>();
                        while ((val = pq.Poll()) != forbidden)
                        {
                            BrowseFacet facet = new BrowseFacet(_predefinedRanges.ElementAt(val), rangeCount.Get(val));
                            facetColl.Insert(0, facet);
                        }
                    }
                    return facetColl;
                }
                else
                {
                    return FacetCountCollector_Fields.EMPTY_FACET_LIST;
                }
            }
            else
            {
                return FacetCountCollector_Fields.EMPTY_FACET_LIST;
            }
        }
        public static IEnumerable <BrowseFacet> GetFacets(FacetSpec ospec, BigSegmentedArray count, int countlength, ITermValueList valList)
        {
            if (ospec != null)
            {
                int minCount = ospec.MinHitCount;
                int max      = ospec.MaxCount;
                if (max <= 0)
                {
                    max = countlength;
                }

                LinkedList <BrowseFacet> facetColl;
                FacetSpec.FacetSortSpec  sortspec = ospec.OrderBy;
                if (sortspec == FacetSpec.FacetSortSpec.OrderValueAsc)
                {
                    facetColl = new LinkedList <BrowseFacet>();
                    for (int i = 1; i < countlength; ++i) // exclude zero
                    {
                        int hits = count.Get(i);
                        if (hits >= minCount)
                        {
                            BrowseFacet facet = new BrowseFacet(valList.Get(i), hits);
                            facetColl.AddLast(facet);
                        }

                        if (facetColl.Count >= max)
                        {
                            break;
                        }
                    }
                }
                else //if (sortspec == FacetSortSpec.OrderHitsDesc)
                {
                    IComparatorFactory comparatorFactory;
                    if (sortspec == FacetSpec.FacetSortSpec.OrderHitsDesc)
                    {
                        comparatorFactory = new FacetHitcountComparatorFactory();
                    }
                    else
                    {
                        comparatorFactory = ospec.CustomComparatorFactory;
                    }

                    if (comparatorFactory == null)
                    {
                        throw new ArgumentException("facet comparator factory not specified");
                    }

                    IComparer <int> comparator = comparatorFactory.NewComparator(new DefaultFacetCountCollectorFieldAccessor(valList), count);
                    facetColl = new LinkedList <BrowseFacet>();
                    int forbidden = -1;
                    IntBoundedPriorityQueue pq = new IntBoundedPriorityQueue(comparator, max, forbidden);

                    for (int i = 1; i < countlength; ++i) // exclude zero
                    {
                        int hits = count.Get(i);
                        if (hits >= minCount)
                        {
                            pq.Offer(i);
                        }
                    }

                    int val;
                    while ((val = pq.Poll()) != forbidden)
                    {
                        BrowseFacet facet = new BrowseFacet(valList[val], count.Get(val));
                        facetColl.AddFirst(facet);
                    }
                }
                return(facetColl);
            }
            else
            {
                return(FacetCountCollector_Fields.EMPTY_FACET_LIST);
            }
        }
        public static IEnumerable<BrowseFacet> GetFacets(FacetSpec ospec, BigSegmentedArray count, int countlength, ITermValueList valList)
        {
            if (ospec != null)
            {
                int minCount = ospec.MinHitCount;
                int max = ospec.MaxCount;
                if (max <= 0) max = countlength;

                LinkedList<BrowseFacet> facetColl;
                FacetSpec.FacetSortSpec sortspec = ospec.OrderBy;
                if (sortspec == FacetSpec.FacetSortSpec.OrderValueAsc)
                {
                    facetColl = new LinkedList<BrowseFacet>();
                    for (int i = 1; i < countlength; ++i) // exclude zero
                    {
                        int hits = count.Get(i);
                        if (hits >= minCount)
                        {
                            BrowseFacet facet = new BrowseFacet(valList.Get(i), hits);
                            facetColl.AddLast(facet);
                        }

                        if (facetColl.Count >= max)
                            break;
                    }
                }
                else //if (sortspec == FacetSortSpec.OrderHitsDesc)
                {
                    IComparatorFactory comparatorFactory;
                    if (sortspec == FacetSpec.FacetSortSpec.OrderHitsDesc)
                    {
                        comparatorFactory = new FacetHitcountComparatorFactory();
                    }
                    else
                    {
                        comparatorFactory = ospec.CustomComparatorFactory;
                    }

                    if (comparatorFactory == null)
                    {
                        throw new ArgumentException("facet comparator factory not specified");
                    }

                    IComparer<int> comparator = comparatorFactory.NewComparator(new DefaultFacetCountCollectorFieldAccessor(valList), count);
                    facetColl = new LinkedList<BrowseFacet>();
                    int forbidden = -1;
                    IntBoundedPriorityQueue pq = new IntBoundedPriorityQueue(comparator, max, forbidden);

                    for (int i = 1; i < countlength; ++i) // exclude zero
                    {
                        int hits = count.Get(i);
                        if (hits >= minCount)
                        {
                            pq.Offer(i);
                        }
                    }

                    int val;
                    while ((val = pq.Poll()) != forbidden)
                    {
                        BrowseFacet facet = new BrowseFacet(valList[val], count.Get(val));
                        facetColl.AddFirst(facet);
                    }
                }
                return facetColl;
            }
            else
            {
                return FacetCountCollector_Fields.EMPTY_FACET_LIST;
            }
        }
Example #38
0
        protected static BrowseHit[] BuildHits(MyScoreDoc[] scoreDocs, SortField[] sortFields,
                                               IDictionary <string, IFacetHandler> facetHandlerMap, bool fetchStoredFields,
                                               IEnumerable <string> termVectorsToFetch, IFacetHandler groupBy, CombinedFacetAccessible[] groupAccessibles)
        {
            BrowseHit[] hits = new BrowseHit[scoreDocs.Length];
            IEnumerable <IFacetHandler> facetHandlers = facetHandlerMap.Values;

            for (int i = scoreDocs.Length - 1; i >= 0; i--)
            {
                MyScoreDoc      fdoc   = scoreDocs[i];
                BoboIndexReader reader = fdoc.reader;
                BrowseHit       hit    = new BrowseHit();
                if (fetchStoredFields)
                {
                    hit.StoredFields = reader.Document(fdoc.Doc);
                }
                if (termVectorsToFetch != null && termVectorsToFetch.Count() > 0)
                {
                    var tvMap = new Dictionary <string, BrowseHit.TermFrequencyVector>();
                    hit.TermFreqMap = tvMap;
                    foreach (string field in termVectorsToFetch)
                    {
                        ITermFreqVector tv = reader.GetTermFreqVector(fdoc.Doc, field);
                        if (tv != null)
                        {
                            int[]    freqs = tv.GetTermFrequencies();
                            string[] terms = tv.GetTerms();
                            tvMap[field] = new BrowseHit.TermFrequencyVector(terms, freqs);
                        }
                    }
                }
                var map    = new Dictionary <string, string[]>();
                var rawMap = new Dictionary <string, object[]>();
                foreach (var facetHandler in facetHandlers)
                {
                    map[facetHandler.Name]    = facetHandler.GetFieldValues(reader, fdoc.Doc);
                    rawMap[facetHandler.Name] = facetHandler.GetRawFieldValues(reader, fdoc.Doc);
                }
                hit.FieldValues    = map;
                hit.RawFieldValues = rawMap;
                hit.DocId          = fdoc.Doc + fdoc.queue.@base;
                hit.Score          = fdoc.Score;
                hit.Comparable     = fdoc.Value;
                if (groupBy != null)
                {
                    hit.GroupField    = groupBy.Name;
                    hit.GroupValue    = hit.GetField(groupBy.Name);
                    hit.RawGroupValue = hit.GetRawField(groupBy.Name);
                    if (groupAccessibles != null &&
                        hit.GroupValue != null &&
                        groupAccessibles != null &&
                        groupAccessibles.Length > 0)
                    {
                        BrowseFacet facet = groupAccessibles[0].GetFacet(hit.GroupValue);
                        hit.GroupHitsCount = facet.FacetValueHitCount;
                    }
                }
                hits[i] = hit;
            }
            return(hits);
        }
Example #39
0
        protected static BrowseHit[] BuildHits(MyScoreDoc[] scoreDocs, SortField[] sortFields,
                                               IDictionary <string, IFacetHandler> facetHandlerMap, bool fetchStoredFields,
                                               ICollection <string> termVectorsToFetch, IFacetHandler groupBy, CombinedFacetAccessible[] groupAccessibles)
        {
            BrowseHit[] hits = new BrowseHit[scoreDocs.Length];
            IEnumerable <IFacetHandler> facetHandlers = facetHandlerMap.Values;

            for (int i = scoreDocs.Length - 1; i >= 0; i--)
            {
                MyScoreDoc        fdoc   = scoreDocs[i];
                BoboSegmentReader reader = fdoc.m_reader;
                BrowseHit         hit    = new BrowseHit();
                if (fetchStoredFields)
                {
                    hit.SetStoredFields(reader.Document(fdoc.Doc));
                }
                if (termVectorsToFetch != null && termVectorsToFetch.Count > 0)
                {
                    var tvMap = new Dictionary <string, IList <BrowseHit.BoboTerm> >();
                    hit.TermVectorMap = tvMap;
                    Fields fds = reader.GetTermVectors(fdoc.Doc);
                    foreach (string field in termVectorsToFetch)
                    {
                        Terms terms = fds.GetTerms(field);
                        if (terms == null)
                        {
                            continue;
                        }

                        TermsEnum                 termsEnum = terms.GetIterator(null);
                        BytesRef                  text;
                        DocsAndPositionsEnum      docsAndPositions = null;
                        List <BrowseHit.BoboTerm> boboTermList     = new List <BrowseHit.BoboTerm>();

                        while ((text = termsEnum.Next()) != null)
                        {
                            BrowseHit.BoboTerm boboTerm = new BrowseHit.BoboTerm();
                            boboTerm.Term    = text.Utf8ToString();
                            boboTerm.Freq    = (int)termsEnum.TotalTermFreq;
                            docsAndPositions = termsEnum.DocsAndPositions(null, docsAndPositions);
                            if (docsAndPositions != null)
                            {
                                docsAndPositions.NextDoc();
                                boboTerm.Positions    = new List <int>();
                                boboTerm.StartOffsets = new List <int>();
                                boboTerm.EndOffsets   = new List <int>();
                                for (int t = 0; t < boboTerm.Freq; ++t)
                                {
                                    boboTerm.Positions.Add(docsAndPositions.NextPosition());
                                    boboTerm.StartOffsets.Add(docsAndPositions.StartOffset);
                                    boboTerm.EndOffsets.Add(docsAndPositions.EndOffset);
                                }
                            }
                            boboTermList.Add(boboTerm);
                        }
                        tvMap.Put(field, boboTermList);
                    }
                }
                var map    = new Dictionary <string, string[]>();
                var rawMap = new Dictionary <string, object[]>();
                foreach (var facetHandler in facetHandlers)
                {
                    map[facetHandler.Name]    = facetHandler.GetFieldValues(reader, fdoc.Doc);
                    rawMap[facetHandler.Name] = facetHandler.GetRawFieldValues(reader, fdoc.Doc);
                }
                hit.FieldValues    = map;
                hit.RawFieldValues = rawMap;
                hit.DocId          = fdoc.Doc + fdoc.m_queue.m_base;
                hit.Score          = fdoc.Score;
                hit.Comparable     = fdoc.Value;
                if (groupBy != null)
                {
                    hit.GroupField    = groupBy.Name;
                    hit.GroupValue    = hit.GetField(groupBy.Name);
                    hit.RawGroupValue = hit.GetRawField(groupBy.Name);
                    if (groupAccessibles != null &&
                        hit.GroupValue != null &&
                        groupAccessibles != null &&
                        groupAccessibles.Length > 0)
                    {
                        BrowseFacet facet = groupAccessibles[0].GetFacet(hit.GroupValue);
                        hit.GroupHitsCount = facet.FacetValueHitCount;
                    }
                }
                hits[i] = hit;
            }
            return(hits);
        }
        // this is really crappy, need to fix it
        private BrowseFacet[] FoldChoices(BrowseFacet[] choices, int max)
        {
            if (max == 0 || choices.Length <= max)
                return choices;
            List<RangeFacet> list = new List<RangeFacet>();

            for (int i = 0; i < choices.Length; i += 2)
            {
                RangeFacet rangeChoice = new RangeFacet();
                if ((i + 1) < choices.Length)
                {
                    if (choices is RangeFacet[])
                    {
                        RangeFacet[] rChoices = (RangeFacet[])choices;
                        object val1 = rChoices[i].Lower;
                        object val2 = rChoices[i + 1].Upper;
                        rangeChoice.SetValues(val1, val2);
                        rangeChoice.HitCount = choices[i].HitCount + choices[i + 1].HitCount;
                    }
                    else
                    {
                        rangeChoice.SetValues(choices[i].Value, choices[i + 1].Value);
                        rangeChoice.HitCount = choices[i].HitCount + choices[i + 1].HitCount;
                    }

                }
                else
                {
                    if (choices is RangeFacet[])
                    {
                        RangeFacet[] rChoices = (RangeFacet[])choices;
                        rangeChoice.SetValues(rChoices[i].Lower, rChoices[i].Upper);
                    }
                    else
                    {
                        rangeChoice.SetValues(choices[i].Value, choices[i].Value);
                    }
                    rangeChoice.HitCount = choices[i].HitCount;
                }
                list.Add(rangeChoice);
            }

            RangeFacet[] result = list.ToArray();
            return FoldChoices(result, max);
        }
 public virtual IEnumerable<BrowseFacet> GetFacets()
 {
     List<BrowseFacet> facets = new List<BrowseFacet>();
     for (int i = 0; i < parent._facetEntries.Length; i++)
     {
         FacetEntry entry = parent._facetEntries[i];
         BrowseFacet facet = new BrowseFacet();
         facet.HitCount = _counts[i];
         facet.Value = entry.value;
         facets.Add(facet);
     }
     return facets;
 }
 public virtual BrowseFacet GetFacet(string @value)
 {
     BrowseFacet facet = null;
     int[] range = RangeFacetHandler.Parse(dataCache, @value);
     if (range != null)
     {
         int sum = 0;
         for (int i = range[0]; i <= range[1]; ++i)
         {
             sum += count[i];
         }
         facet = new BrowseFacet(@value, sum);
     }
     return facet;
 }
        public virtual IEnumerable <BrowseFacet> GetFacets()
        {
            if (_closed)
            {
                throw new InvalidOperationException("This instance of count collector was already closed");
            }
            int maxCnt = _fspec.MaxCount;

            if (maxCnt <= 0)
            {
                maxCnt = int.MaxValue;
            }
            int minHits             = _fspec.MinHitCount;
            List <BrowseFacet> list = new List <BrowseFacet>();

            int                     cnt   = 0;
            string                  facet = null;
            FacetIterator           iter  = (FacetIterator)this.Iterator();
            IComparer <BrowseFacet> comparator;

            if (FacetSpec.FacetSortSpec.OrderValueAsc.Equals(_fspec.OrderBy))
            {
                while (!string.IsNullOrEmpty((facet = iter.Next(minHits))))
                {
                    // find the next facet whose combined hit count obeys minHits
                    list.Add(new BrowseFacet(Convert.ToString(facet), iter.Count));
                    if (++cnt >= maxCnt)
                    {
                        break;
                    }
                }
            }
            else if (FacetSpec.FacetSortSpec.OrderHitsDesc.Equals(_fspec.OrderBy))
            {
                comparator = new BrowseFacetComparator();
                if (maxCnt != int.MaxValue)
                {
                    // we will maintain a min heap of size maxCnt
                    // Order by hits in descending order and max count is supplied
                    var queue = CreatePQ(maxCnt, comparator);
                    int qsize = 0;
                    while ((qsize < maxCnt) && !string.IsNullOrEmpty((facet = iter.Next(minHits))))
                    {
                        queue.Add(new BrowseFacet(facet, iter.Count));
                        qsize++;
                    }
                    if (!string.IsNullOrEmpty(facet))
                    {
                        BrowseFacet rootFacet = (BrowseFacet)queue.Top();
                        minHits = rootFacet.FacetValueHitCount + 1;
                        // facet count less than top of min heap, it will never be added
                        while (!string.IsNullOrEmpty((facet = iter.Next(minHits))))
                        {
                            rootFacet.Value = facet;
                            rootFacet.FacetValueHitCount = iter.Count;
                            rootFacet = (BrowseFacet)queue.UpdateTop();
                            minHits   = rootFacet.FacetValueHitCount + 1;
                        }
                    }
                    // at this point, queue contains top maxCnt facets that have hitcount >= minHits
                    while (qsize-- > 0)
                    {
                        // append each entry to the beginning of the facet list to order facets by hits descending
                        list.Insert(0, (BrowseFacet)queue.Pop());
                    }
                }
                else
                {
                    // no maxCnt specified. So fetch all facets according to minHits and sort them later
                    while (!string.IsNullOrEmpty((facet = iter.Next(minHits))))
                    {
                        list.Add(new BrowseFacet(facet, iter.Count));
                    }
                    list.Sort(comparator);
                }
            }
            else // FacetSortSpec.OrderByCustom.equals(_fspec.getOrderBy()
            {
                comparator = _fspec.CustomComparatorFactory.NewComparator();
                if (maxCnt != int.MaxValue)
                {
                    var         queue       = CreatePQ(maxCnt, comparator);
                    BrowseFacet browseFacet = new BrowseFacet();
                    int         qsize       = 0;
                    while ((qsize < maxCnt) && !string.IsNullOrEmpty((facet = iter.Next(minHits))))
                    {
                        queue.Add(new BrowseFacet(facet, iter.Count));
                        qsize++;
                    }
                    if (!string.IsNullOrEmpty(facet))
                    {
                        while (!string.IsNullOrEmpty((facet = iter.Next(minHits))))
                        {
                            // check with the top of min heap
                            browseFacet.FacetValueHitCount = iter.Count;
                            browseFacet.Value = facet;
                            browseFacet       = (BrowseFacet)queue.InsertWithOverflow(browseFacet);
                        }
                    }
                    // remove from queue and add to the list
                    while (qsize-- > 0)
                    {
                        list.Insert(0, (BrowseFacet)queue.Pop());
                    }
                }
                else
                {
                    // order by custom but no max count supplied
                    while (!string.IsNullOrEmpty((facet = iter.Next(minHits))))
                    {
                        list.Add(new BrowseFacet(facet, iter.Count));
                    }
                    list.Sort(comparator);
                }
            }
            return(list);
        }