<commit_before>﻿//* Bobo Browse Engine - High performance faceted/parametric search implementation 
//* that handles various types of semi-structured data.  Originally written in Java.
//*
//* Ported and adapted for C# by <NAME>.
//*
//* Copyright (C) 2005-2015  <NAME>
//*
//* Licensed under the Apache License, Version 2.0 (the "License");
//* you may not use this file except in compliance with the License.
//* You may obtain a copy of the License at
//*
//*   http://www.apache.org/licenses/LICENSE-2.0
//*
//* Unless required by applicable law or agreed to in writing, software
//* distributed under the License is distributed on an "AS IS" BASIS,
//* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//* See the License for the specific language governing permissions and
//* limitations under the License.

// Version compatibility level: 3.2.0
namespace BoboBrowse.Net.Facets.Impl
{
    using BoboBrowse.Net.Facets.Data;
    using BoboBrowse.Net.Support;
    using BoboBrowse.Net.Util;
    using Lucene.Net.Util;
    using System.Collections.Generic;
    using System.Linq;

    public class BucketFacetCountCollector : IFacetCountCollector
    {
        private readonly string _name;
        private readonly DefaultFacetCountCollector _subCollector;
        private readonly FacetSpec _ospec;
        private readonly IDictionary<string, string[]> _predefinedBuckets;
        private BigSegmentedArray _collapsedCounts;
        private TermStringList _bucketValues;
        private readonly int _numdocs;

        public BucketFacetCountCollector(string name, DefaultFacetCountCollector subCollector, FacetSpec ospec, IDictionary<string, string[]> predefinedBuckets, int numdocs)
        {
            _name = name;
            _subCollector = subCollector;
            _ospec = ospec;
            _numdocs = numdocs;

            _predefinedBuckets = predefinedBuckets;
            _collapsedCounts = null;

            _bucketValues = new TermStringList();
            _bucketValues.Add("");

            List<string> bucketArray = _predefinedBuckets.Keys.ToList();
            bucketArray.Sort();
            foreach (string bucket in bucketArray)
            {
                _bucketValues.Add(bucket);
            }
            _bucketValues.Seal();
        }

        private BigSegmentedArray GetCollapsedCounts()
        {
            if (_collapsedCounts == null)
            {
                _collapsedCounts = new LazyBigIntArray(_bucketValues.Count);
                FacetDataCache dataCache = _subCollector.DataCache;
                ITermValueList subList = dataCache.ValArray;
                BigSegmentedArray subcounts = _subCollector.Count;
                BitVector indexSet = new BitVector(subcounts.Size());
                int c = 0;
                int i = 0;
                foreach (string val in _bucketValues)
                {<commit_msg>Updated BucketFacetCountCollector to 4.0.2 compatibility.<commit_after>﻿//* Bobo Browse Engine - High performance faceted/parametric search implementation 
//* that handles various types of semi-structured data.  Originally written in Java.
//*
//* Ported and adapted for C# by <NAME>.
//*
//* Copyright (C) 2005-2015  <NAME>
//*
//* Licensed under the Apache License, Version 2.0 (the "License");
//* you may not use this file except in compliance with the License.
//* You may obtain a copy of the License at
//*
//*   http://www.apache.org/licenses/LICENSE-2.0
//*
//* Unless required by applicable law or agreed to in writing, software
//* distributed under the License is distributed on an "AS IS" BASIS,
//* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//* See the License for the specific language governing permissions and
//* limitations under the License.

// Version compatibility level: 4.0.2
namespace BoboBrowse.Net.Facets.Impl
{
    using BoboBrowse.Net.Facets.Data;
    using BoboBrowse.Net.Support;
    using BoboBrowse.Net.Util;
    using Lucene.Net.Util;
    using System.Collections.Generic;
    using System.Linq;

    public class BucketFacetCountCollector : IFacetCountCollector
    {
        private readonly string _name;
        private readonly DefaultFacetCountCollector _subCollector;
        private readonly FacetSpec _ospec;
        private readonly IDictionary<string, string[]> _predefinedBuckets;
        private BigSegmentedArray _collapsedCounts;
        private readonly TermStringList _bucketValues;
        private readonly int _numdocs;

        public BucketFacetCountCollector(string name, DefaultFacetCountCollector subCollector, FacetSpec ospec, IDictionary<string, string[]> predefinedBuckets, int numdocs)
        {
            _name = name;
            _subCollector = subCollector;
            _ospec = ospec;
            _numdocs = numdocs;

            _predefinedBuckets = predefinedBuckets;
            _collapsedCounts = null;

            _bucketValues = new TermStringList();
            _bucketValues.Add("");

            List<string> bucketArray = _predefinedBuckets.Keys.ToList();
            bucketArray.Sort();
            foreach (string bucket in bucketArray)
            {
                _bucketValues.Add(bucket);
            }
            _bucketValues.Seal();
        }

        private BigSegmentedArray GetCollapsedCounts()
        {
            if (_collapsedCounts == null)
            {
                _collapsedCounts = new LazyBigIntArray(_bucketValues.Count);
                IFacetDataCache dataCache = _subCollector.DataCache;
                ITermValueList subList = dataCache.ValArray;
                BigSegmentedArray subcounts = _subCollector.Count;
                FixedBitSet indexSet = new FixedBitSet(subcounts.Size());
                int c = 0;
                int i = 0;
                foreach (string val in _bucketValues)
                {
{'fraction_non_alphanumeric': 0.07961131946812137, 'fraction_numerical': 0.006307534947153085, 'mean_word_length': 2.428988895382817, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2499408', 'n_tokens_mistral': 1612, 'n_tokens_neox': 1535, 'n_words': 465}