<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>, <NAME>, and zhengchun.
//*
//* 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
{
    using BoboBrowse.Net.Support;
    using Lucene.Net.Documents;
    using Lucene.Net.Index;
    using Lucene.Net.Search;
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;

    ///<summary>A hit from a browse.</summary>
    [Serializable]
    public class BrowseHit
    {
        //private static long serialVersionUID = 1L; // NOT USED

        [Serializable]
        public class BoboTerm
        {
            //private static long serialVersionUID = 1L; // NOT USED

            public BoboTerm()
            {
                Positions = new List<int>();
                StartOffsets = new List<int>();
                EndOffsets = new List<int>();
            }

            public string Term { get; set; }
            public int Freq { get; set; }
            public IList<int> Positions { get; set; }
            public IList<int> StartOffsets { get; set; }
            public IList<int> EndOffsets { get; set; }
        }

        [Serializable]
        public class SerializableField
        {

            //private static long serialVersionUID = 1L; // NOT USED
            private readonly string name;

            /** Field's value */
            private object fieldsData;

            public SerializableField(IndexableField field)
            {
                // TODO: Fix this property and push to Lucene.Net
                name = field.Name();
                if (field.NumericValue != null)
                {
                    fieldsData = field.NumericValue;
                }
                else if (field.StringValue != null)
                {
                    fieldsData = field.StringValue;
                }
                else if (field.BinaryValue() != null)
                {
                    // TODO: Fix this property and push to Lucene.Net
                    fieldsData = field.BinaryValue().Bytes;
                }
                else
                {
                    throw new NotSupportedException("Doesn't support this field type so far");
                }
            }

            public string Name
            {
                get { return name; }
            }

            public string StringValue
            {
                get
                {
                    if (fieldsData is string || NumericUtil.IsNumeric(fieldsData))
                    {
                        return fieldsData.ToString();
                    }
                    else
                    {
                        return null;
                    }
                }
            }

            public object NumericValue
            {
                get
                {
                    if (NumericUtil.IsNumeric(fieldsData))
                    {
                        return (Decimal)fieldsData;
                    }
                    else
                    {
                        return null;
                    }
                }
            }

            public byte[] BinaryValue
            {
                get
                {
                    if (fieldsData is byte[])
                    {
                        return (byte[])fieldsData;
                    }
                    else
                    {
                        return null;
                    }
                }
            }

            public override bool Equals(object o)
            {
                if (!(o is SerializableField))
                {
                    return false;
                }
                SerializableField other = (SerializableField)o;
                if (!name.Equals(other.Name))
                {
                    return false;
                }
                string value = StringValue;
                if (value != null)
                {
                    if (value.Equals(other.StringValue))
                    {
                        return true;
                    }
                    return false;
                }
                byte[] binValue = BinaryValue;
                if (binValue != null)
                {
                    return Arrays.Equals(binValue, other.BinaryValue);
                }
                return false;
            }
        }


        [Serializable]
        public class SerializableExplanation
        {
            /**
             *
             */
            //private static const long serialVersionUID = 1L; // NOT USED

            private float value; // the value of this node
            private string description;
            private IList<SerializableExplanation> details; // sub-explanations

            public SerializableExplanation(Explanation explanation)
            {
                Value = explanation.Value;
                Description = explanation.Description;
                Explanation[] details = explanation.Details;
                if (details == null)
                {
                    return;
                }
                foreach (Explanation exp in details)
                {
                    AddDetail(new SerializableExplanation(exp));
                }
            }

<commit_msg>Added missing GetHashCode implementation for BrowseHit.SerializableField.<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>, <NAME>, and zhengchun.
//*
//* 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
{
    using BoboBrowse.Net.Support;
    using Lucene.Net.Documents;
    using Lucene.Net.Index;
    using Lucene.Net.Search;
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;

    ///<summary>A hit from a browse.</summary>
    [Serializable]
    public class BrowseHit
    {
        //private static long serialVersionUID = 1L; // NOT USED

        [Serializable]
        public class BoboTerm
        {
            //private static long serialVersionUID = 1L; // NOT USED

            public BoboTerm()
            {
                Positions = new List<int>();
                StartOffsets = new List<int>();
                EndOffsets = new List<int>();
            }

            public string Term { get; set; }
            public int Freq { get; set; }
            public IList<int> Positions { get; set; }
            public IList<int> StartOffsets { get; set; }
            public IList<int> EndOffsets { get; set; }
        }

        [Serializable]
        public class SerializableField
        {

            //private static long serialVersionUID = 1L; // NOT USED
            private readonly string name;

            /** Field's value */
            private object fieldsData;

            public SerializableField(IndexableField field)
            {
                // TODO: Fix this property and push to Lucene.Net
                name = field.Name();
                if (field.NumericValue != null)
                {
                    fieldsData = field.NumericValue;
                }
                else if (field.StringValue != null)
                {
                    fieldsData = field.StringValue;
                }
                else if (field.BinaryValue() != null)
                {
                    // TODO: Fix this property and push to Lucene.Net
                    fieldsData = field.BinaryValue().Bytes;
                }
                else
                {
                    throw new NotSupportedException("Doesn't support this field type so far");
                }
            }

            public string Name
            {
                get { return name; }
            }

            public string StringValue
            {
                get
                {
                    if (fieldsData is string || NumericUtil.IsNumeric(fieldsData))
                    {
                        return fieldsData.ToString();
                    }
                    else
                    {
                        return null;
                    }
                }
            }

            public object NumericValue
            {
                get
                {
                    if (NumericUtil.IsNumeric(fieldsData))
                    {
                        return (Decimal)fieldsData;
                    }
                    else
                    {
                        return null;
                    }
                }
            }

            public byte[] BinaryValue
            {
                get
                {
                    if (fieldsData is byte[])
                    {
                        return (byte[])fieldsData;
                    }
                    else
                    {
                        return null;
                    }
                }
            }

            public override bool Equals(object o)
            {
                if (!(o is SerializableField))
                {
                    return false;
                }
                SerializableField other = (SerializableField)o;
                if (!name.Equals(other.Name))
                {
                    return false;
                }
                string value = StringValue;
                if (value != null)
                {
                    if (value.Equals(other.StringValue))
                    {
                        return true;
                    }
                    return false;
                }
                byte[] binValue = BinaryValue;
                if (binValue != null)
                {
                    return Arrays.Equals(binValue, other.BinaryValue);
                }
                return false;
            }

            // Required by .NET because Equals() was overridden.
            // Source: http://stackoverflow.com/questions/70303/how-do-you-implement-gethashcode-for-structure-with-two-string#21604191
            public override int GetHashCode()
            {
                unchecked
                {
                    int hashCode = 0;

                    // String properties
                    hashCode = (hashCode * 397) ^ (name != null ? name.GetHashCode() : string.Empty.GetHashCode());

                    string value = StringValue;
                    hashCode = (hashCode * 397) ^ (value != null ? value.GetHashCode() : string.Empty.GetHashCode());

                    // int properties
                    //hashCode = (hashCode * 397) ^ _hitcount;

                    return hashCode;
                }
            }
        }


        [Serializable]
        public class SerializableExplanation
        {
            /**
             *
             */
            //private static const long serialVersionUID = 1L; // NOT USED

            private float value; // the value of this node
            private string description;
            private IList<SerializableExplanation> details; // sub-explanations

            public SerializableExplanation(Explanation explanation)
            {
                Value = explanation.Value;
                Description = explanation.Description;
                Explanation[] details = explanation.Details;
                if (details == null)
                {
                    return;
                }
                foreach (Explanation exp in details)
                {
                    AddDetail(new SerializableExplanation(exp));
                }
            }


{'fraction_non_alphanumeric': 0.07733578600444546, 'fraction_numerical': 0.004675404307503641, 'mean_word_length': 1.0707824154896048, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 27, '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': '6880221', 'n_tokens_mistral': 3149, 'n_tokens_neox': 2841, 'n_words': 845}